Simple Mysql 8 Setup | Docker Swarm

You need linux server, docker installed and swarm mode initiated.

Make a dir for mysql docker and other files:

mkdir mysql8 && cd mysql8
mkdir conf.d dbdata
nano conf.d/custom.ini
[mysqld]
sql-mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
default-authentication-plugin=mysql_native_password
character-set-server=utf8
collation-server=utf8_general_ci
nano docker-compose.yml
version: "3.7"

services:

  prod:
    image: mysql:8.0
    hostname: mysql-8
    command: '--default-authentication-plugin=mysql_native_password'
    networks:
      - durbok-net
    deploy:
      placement:
        constraints:
        - node.role == manager
      replicas: 1
      restart_policy:
        condition: on-failure
    volumes:
      - ./conf.d:/etc/mysql/conf.d
      - ./dbdata:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: urrootpass

networks:
  durbok-net:
    external: true

Deploy:

docker stack deploy -c docker-compose.yml mysql8

Wait a bit for docker to pull images. Then enter mysql container and create user and database for next project or app.

docker exec -it mysql8_prod.1.bg2t4nj6nb358wuupsino9nur bash
root@mysql-8:/# 
root@mysql-8:/# mysql -u root -p

Here are some mysql commands:

Mysql Basics
Mysql