DEV Community

Cover image for Encountered 'Permission denied' Error When Starting MySQL Container on Ubuntu 20.04.2 LTS
Kenta Takeuchi
Kenta Takeuchi

Posted on • Originally published at bmf-tech.com

Encountered 'Permission denied' Error When Starting MySQL Container on Ubuntu 20.04.2 LTS

This article was originally published on bmf-tech.com.

Overview

When attempting to start a MySQL container on Ubuntu 20.04.2 LTS, the following error occurs, causing the container to fail to start.

Could not open file '/var/log/mysql/mysql-error.log' for error logging: Permission deniedโ€
Enter fullscreen mode Exit fullscreen mode

Dockerfile

The Dockerfile where the issue occurred.

docker-compose.yml (partial excerpt)

version: '3.2'
services:
  mysql:
    container_name: "example-mysql"
    env_file: ./mysql/.env
    build:
        context: "./mysql"
        dockerfile: "Dockerfile"
    ports:
      - "3306:3306"
    volumes:
      - ./mysql/data:/var/lib/mysql
      - ./mysql/initdb.d:/docker-entrypoint-initdb.d
      - ./mysql/log:/var/log/mysql
Enter fullscreen mode Exit fullscreen mode

Dockerfile

FROM --platform=linux/amd64 mysql:8.0.26

ADD ./conf.d/my.cnf /etc/mysql/conf.d/my.cnf

CMD ["mysqld"]
Enter fullscreen mode Exit fullscreen mode

Checking the Mount Source

$ ls -la mysql
drwxrwxrwx  7 systemd-coredump example-app 4096 Sep 12 23:10 data
Enter fullscreen mode Exit fullscreen mode

An unfamiliar user named systemd-coredump appears.

systemd-coredump

Checking the user on the host, systemd-coredump has uid 999.

$ cat /etc/passwd | grep systemd-coredump
systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
Enter fullscreen mode Exit fullscreen mode

The user inside the MySQL container likely has uid 999, which is probably the cause?

Solution

Add user: 1000:1000 to docker-compose.yml.

docker-compose.yml (partial excerpt)

version: '3.2'
services:
  mysql:
    container_name: "example-mysql"
    env_file: ./mysql/.env
    build:
        context: "./mysql"
        dockerfile: "Dockerfile"
    ports:
      - "3306:3306"
    volumes:
      - ./mysql/data:/var/lib/mysql
      - ./mysql/initdb.d:/docker-entrypoint-initdb.d
      - ./mysql/log:/var/log/mysql
    user: 1000:1000
Enter fullscreen mode Exit fullscreen mode

It might be better to pass the uid and gid from the host instead of hardcoding them.

Thoughts

This issue did not occur on Docker for Mac, so I'm glad I was able to notice it.

References

Top comments (0)