DEV Community

loading...

5/30 TIL: mysql Docker image, Unix Domain Socket

David Hwang
・1 min read

Docker Compose

  • Do a 'docker-compose -f nameOfYourDockerComposeFile build' if you need your changes in Dockerfile to be reflected—because simply doing 'docker-compose up' doesn't rebuild an image

Docker mysql image

  • Configuration options can be passed as flags in the command line. Ex) --character-set-server=utf8mb4
  • When a mysql container is started for the first time, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. So we can populate our mysql services by mounting a SQL dump into that directory. In our example below, we would store our .sql files in db/init and mount it to /docker-entrypoint-initdb.d under volumes:
services:
  db:
    container_name: mysql
    image: mysql
    restart: always
    environment:
      MYSQL_USER: user1
      MYSQL_PASSWORD: test
      MYSQL_ROOT_PASSWORD: test
      MYSQL_DATABASE: users
    ports:
      - '3306:3306'
    volumes:
      - mysql_db:/var/lib/mysql
      - ./db/init:/docker-entrypoint-initdb.d
    command:
      [
        'mysqld',
        '--character-set-server=utf8mb4',
        '--collation-server=utf8mb4_unicode_ci',
      ]
volumes:
mysql_db:
Enter fullscreen mode Exit fullscreen mode

Unix Domain Socket

Discussion (0)