0

I'm trying to add mysql to my docker project but I keep getting an error

db_1        | 2020-06-05T18:09:28.588053Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.20) initializing of server in progress as process 43
db_1        | 2020-06-05T18:09:28.611235Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
db_1        | 2020-06-05T18:09:28.611255Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
db_1        | 2020-06-05T18:09:28.613001Z 0 [ERROR] [MY-010119] [Server] Aborting
db_1        | 2020-06-05T18:09:28.613491Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.20)  MySQL Community Server - GPL.

When I do docker ps I see

CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS                          PORTS                    NAMES
9f561510f33d        frontend               "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes                    0.0.0.0:3000->3000/tcp   frontend_1
2c3f88dc6f6b        backend                "python3 manage.py r…"   5 minutes ago       Up 5 minutes                    0.0.0.0:8000->8000/tcp   backend_1
d0768da38e93        mysql:latest           "docker-entrypoint.s…"   5 minutes ago       Restarting (1) 24 seconds ago                            db_1

I cd into var/lib for container 2c3f88dc6f6b and don't see a mysql dir. Not sure if that might be the issue but if it is why isnt there a mysql folder?

Why am I seeing that error?

docker-compose.yml

version: "3.2"
services:
  backend:
    build: ./backend
    volumes:
      - ./backend:/app/backend
    ports:
      - "8000:8000"
    stdin_open: true
    tty: true
    command: python3 manage.py runserver 0.0.0.0:8000
    links:
      - db
  frontend:
    build: ./frontend
    volumes:
      - ./frontend:/app
      # One-way volume to use node_modules from inside image
      - /app/node_modules
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=development
      - CHOKIDAR_USEPOLLING=true
    depends_on:
      - backend
    tty: true
    command: npm start
  db:
    image: mysql:latest
    restart: always
    volumes:
      - "./.mysql/db:/var/lib/mysql"
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: test
      MYSQL_USER: root
      MYSQL_PASSWORD: root
    ports:
      - "3306:3306"
MalcolmInTheCenter
  • 1,376
  • 6
  • 27
  • 47

3 Answers3

0

This errors appear when you're trying to mount a volume and for your env vars, I'm using Windows

mysql:
    image: mysql:8.0.17
    container_name: localmysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 123456
    ports:
      - 3306:3306
    volumes:
      - C:\containers_data\mysql:/var/lib/mysql

Other observations:

  1. You don't need to do link in backend, just put db like host name
  2. backend depends_on db

check my repo on github: https://github.com/buster95/dockerinfra

halfer
  • 19,824
  • 17
  • 99
  • 186
buster95
  • 640
  • 7
  • 7
0

This is because there is something wrong in local directory ./.mysql/db. Have you tried to remove all data in this directory as suggested in the error message ?

NicoM
  • 125
  • 5
0

I figured it out I was, I had to make the changes below.

version: "3.2"
services:
  backend:
    build: ./backend
    volumes:
      - ./backend:/app/backend
    ports:
      - "8000:8000"
    stdin_open: true
    tty: true
    command: python3 manage.py runserver 0.0.0.0:8000
    links:
      - db
  frontend:
    build: ./frontend
    volumes:
      - ./frontend:/app
      # One-way volume to use node_modules from inside image
      - /app/node_modules
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=development
      - CHOKIDAR_USEPOLLING=true
    depends_on:
      - backend
    tty: true
    command: npm start
  db:
    image: mysql:latest
    restart: always
    volumes:
      - db_data:/var/lib/mysql  #<------------HAD TO ADD THIS
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: test
      MYSQL_USER: root
      MYSQL_PASSWORD: root
    ports:
      - "3306:3306"
volumes:#<------------HAD TO ADD THIS
  db_data: {}#<------------HAD TO ADD THIS
MalcolmInTheCenter
  • 1,376
  • 6
  • 27
  • 47