Ivan Kuzminov
Ivan Kuzminov

Reputation: 35

How to save my databases between restart mysql in Docker container

I've run mysql in Docker (Docker for Windows 1.12.6, not docker toolbox) with command

docker run --name mysqldb -v /d/databases/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d -p 3306:3306 mysql:5.7

And when I've done it first time everything was great. How I've docker container with mysql and database directory on host machine mount as docker container volume.

But when I try to start container agan with command docker start mysqldb I have error Error response from daemon: mkdir /d: file exists Error: failed to start containers: mysqldb

What am I doing wrong? Is there any way to save my databases between container and docker restart?

UPD This is out of docker ps -a

3b5b6cb91107        mysql:5.7           "docker-entrypoint.sh"   9 hours ago         Up 15 seconds       0.0.0.0:3306->3306/tcp   mysqldb

Container has been started but volume /var/lib/mysql is no longer mount to host directory.

"Mounts": [
    {
        "Source": "/d/databases/mysql",
        "Destination": "/var/lib/mysql",
        "Mode": "",
        "RW": true,
        "Propagation": "rprivate"
    }
],

Upvotes: 1

Views: 2687

Answers (1)

emme
emme

Reputation: 225

This is little strange because i executed the same command with my database container and it is working fine everytime.

docker run --name main-database -e DB_HOST=asas -e DB_PORT=testing -p 3306 -v /home/mahesh/projects/django/tmp/mysql:/var/lib/mysql main/database

Could you please upload the output of :

docker ps -a

And please check if the container is in exited state.

UPDATE : What i can see is your container is up now

I think you should start fresh:

Please stop the container using docker stop container-id

Then remove it docker rm container-id

Delete the image if exists docker rmi image-id

Now run your command with --rm flag

docker run --rm --name mysqldb -v /somedir_in_your_home/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d -p 3306:3306 mysql:5.7

Upvotes: 1

Related Questions