3

I'm getting the following error after I run docker-compose up. How do I resolve this?

db_1          | chown: changing ownership of '/var/lib/mysql/': Permission denied
db_1          | chown: changing ownership of '/var/lib/mysql/@0020liquordb': Permission denied
db_1          | chown: changing ownership of '/var/lib/mysql/@0020liquordb/db.opt': Permission denied
db_1          | chown: changing ownership of '/var/lib/mysql/auto.cnf': Permission denied
db_1          | chown: changing ownership of '/var/lib/mysql/ca-key.pem': Permission denied
db_1          | chown: changing ownership of '/var/lib/mysql/ca.pem': Permission denied
db_1          | chown: changing ownership of '/var/lib/mysql/client-cert.pem': Permission denied
db_1          | chown: changing ownership of '/var/lib/mysql/client-key.pem': Permission denied

Dockerfile

FROM python:3.7


ENV PYTHONUNBUFFERED 1

ADD requirements.txt /app/

WORKDIR /app/

RUN pip install --upgrade pip


RUN pip install -r requirements.txt

docker-compose.yml

version: '3'

services:

  # Redis - result backend
  redis:
    image: redis:2.8.19
    hostname: redis

  # RabbitMQ - queue
  rabbit:
    hostname: rabbit
    image: rabbitmq:3-management
    environment:
      - RABBITMQ_DEFAULT_USER=test
      - RABBITMQ_DEFAULT_PASS=test
    ports:
      - "5672:5672"  
      - "15672:15672"  # here, we can access rabbitmq management plugin


  nginx:
    image: nginx:alpine
    container_name: nginx

    restart: always

    ports:
      - "7000:7000"
      - "443:443"

    depends_on:
      - web

    volumes:
      - /app:/app
      - ./config/nginx:/etc/nginx/conf.d
      - /static:/app/static # <-- bind the static volume
      - media_volume:/media  # <-- bind the media volume

  db:
    restart: always
    image: mysql:5.7
    command: --default-authentication-plugin=mysql_native_password
    volumes:
      # - ./init-db:/docker-entrypoint-initdb.d
      - ./data-db:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: test
      MYSQL_DATABASE: test
    ports:
      - "3306:3306"


  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    environment:
      MYSQL_USERNAME: test
      MYSQL_ROOT_PASSWORD: test
    restart: always
    ports:
      - 8082:80
    volumes:
      - /sessions


  web:
    build:
      context: .
      dockerfile: Dockerfile
    hostname: web
    restart: always
    command: sh ./run_web.sh
    volumes:
      - .:/app
      - /static:/app/static

    depends_on:
      - db

    links:
      - rabbit
      - redis

    expose: 
    - "7000"


  # Celery worker
  worker:
    build:
      context: .
      dockerfile: Dockerfile
    command: sh ./run_celery.sh

    volumes:
      - .:/app
    links:
      - rabbit
      - redis

    depends_on:
      - rabbit

volumes:
  media_volume:  # <-- declare the media volume
  api_data:
  my-db:
  init-db:
  data-db:
Philip Mutua
  • 6,016
  • 12
  • 41
  • 84

2 Answers2

14

You can try to edit the db service in docker-compose.yml with the following changes:

volumes:
  # - ./init-db:/docker-entrypoint-initdb.d
  - ./data-db:/var/lib/mysql:rw # <- permissions
user: mysql # <- user, should be 'mysql'
Petar Nikov
  • 1,159
  • 10
  • 17
0

In your DB section in the docker compose file

Change this:

  • ./data-db:/var/lib/mysql

For this:

  • data-db:/var/lib/mysql

Is not a bind to a folder what you have, data-db is a volume like the media one

matiasm77
  • 87
  • 1
  • 3
  • 2
    Changing this has led to the loss of data. Luckily I was using a test server and I have the backup DB. – Philip Mutua Mar 31 '20 at 12:50
  • oh boy.... sorry about that :( have you tried to change your local folders permissions? https://stackoverflow.com/questions/43593736/used-chown-for-var-lib-mysql-to-change-owner-from-root-now-getting-error-1049 – matiasm77 Mar 31 '20 at 14:21