1

I used docker commit and now the container won't run properly. Should I:

  • specify a new data folder within the container, so it will get deleted when I delete the container
  • delete the host folder contents under /var/lib/mysql?

What I did was I started a Docker container:

docker run -p 33069:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=test -d mysql:8.0.26 mysqld --default-authentication-plugin=mysql_native_password

Configured some stuff like remote root login, inserted some data into it. Then I wanted to back it up and did:

docker commit -p 6b836bfdf062 backup-mysql8

Which went OK:

root@server:/home/user# docker images | grep mysql
backup-mysql8                                             latest                1effec593a03   45 minutes ago   514MB

Then I stopped and removed the old container. And tried to start a new one from the backup:

docker run -p 33069:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=test -d mysql:8.0.26 mysqld --default-authentication-plugin=mysql_native_password -d backup-mysql8

After a few seconds, it would just die.

root@server:/var/lib/mysql# docker ps -a
CONTAINER ID   IMAGE                                                                 COMMAND                  CREATED          STATUS                      PORTS                                                                                  NAMES
13b17d3af8f7   mysql:8.0.26                                                          "docker-entrypoint.s…"   21 minutes ago   Exited (1) 21 minutes ago                                                                                          some-mysql

I looked at the logs:

docker logs 13b17d3af8f7

And found this:

2021-09-10T15:15:37.074480Z 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.

I used inspect and saw that this new host is using my host folder /var/lib/mysql, is that what this means?

docker inspect 13b17d3af8f7

docker using local host /var/lib/mysql

The problem is that that folder on my host machine is already being used and I don't think it's used by the previous container.

root@server:/var/lib/mysql# ls -l
total 110652
-rw-r----- 1 mysql mysql       56 feb 13  2020 auto.cnf
-rw------- 1 mysql mysql     1676 feb 13  2020 ca-key.pem
-rw-r--r-- 1 mysql mysql     1112 feb 13  2020 ca.pem
-rw-r--r-- 1 mysql mysql     1112 feb 13  2020 client-cert.pem
-rw------- 1 mysql mysql     1680 feb 13  2020 client-key.pem
-rw-r--r-- 1 mysql mysql        0 iul 28 06:01 debian-5.7.flag
-rw-r----- 1 mysql mysql      291 feb 13  2020 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 feb 13  2020 ibdata1
-rw-r----- 1 mysql mysql 50331648 feb 13  2020 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 feb 13  2020 ib_logfile1
drwxr-x--- 2 mysql mysql     4096 feb 13  2020 mysql
drwxr-x--- 2 mysql mysql     4096 feb 13  2020 performance_schema
-rw------- 1 mysql mysql     1680 feb 13  2020 private_key.pem
-rw-r--r-- 1 mysql mysql      452 feb 13  2020 public_key.pem
-rw-r--r-- 1 mysql mysql     1112 feb 13  2020 server-cert.pem
-rw------- 1 mysql mysql     1676 feb 13  2020 server-key.pem
drwxr-x--- 2 mysql mysql    12288 feb 13  2020 sys

What and how to do it?

2
  • 1
    You probably don't ever want to use docker commit. In this particular case, docker commit mysql doesn't save because the data is always in a volume. More generally there is some discussion on How can I backup a Docker-container with its data-volumes?. But docker commit isn't part of a reproducible work flow. Commented Sep 10, 2021 at 18:31
  • I don't care about the data. I'm asking why a new container won't start using the old container's volume. Commented Sep 13, 2021 at 7:47

1 Answer 1

4

if you need persistent data stored, you should map /var/lib/mysql to a host folder instead.

e.g.

docker run -p 33069:3306 --name some-mysql -v ./mydata:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=test -d mysql:8.0.26 mysqld --default-authentication-plugin=mysql_native_password

Update: docker inspect output just represent the section VOLUME ["/var/lib/mysql"] in Dockerfile.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.