1

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"
    }
],
Ivan Kuzminov
  • 35
  • 1
  • 6
  • Can you perform `docker ps -a` to verify the mysql container isn't running anymore and check it logs: `docker logs container-id` – lvthillo Jan 17 '17 at 08:40
  • mysql container isn't running anymore and check it log has no errors. The problem is something else – Ivan Kuzminov Jan 17 '17 at 09:24
  • Does this answer your question? [retain the data inside database using docker](https://stackoverflow.com/questions/34309961/retain-the-data-inside-database-using-docker) – Musa Haidari May 26 '20 at 06:50

1 Answers1

1

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
emme
  • 215
  • 1
  • 8