1

I want to run a mysql container in Docker. The Dockerfile that I use is the Dockerfile defined in the official repo[here]. I only extended this Dockerfile with 2 more lines so I can import a init sql file, like this :

    ADD my-init-file.sql /my-init-file.sql 
    CMD ["mysqld", "--init-file=/my-init-file.sql"]

I want to run this instance as a daemon but when I execute this command, from the documentation:

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql

The container exits automatically. I want to run it as a daemon so I can link apps(like a wordpress site) in another container to the mysql database.

Maybe I am missing something. Can anyone show me how ?

[EDIT] I forgot to say that I ran docker logs my-container after starting the container and there is no error :

Running mysql_install_db ...
Finished mysql_install_db

docker ps shows no running container. My guess is the command executes successfully but the mysqld daemon does not start.

2 Answers 2

1

Your Dockerfile seems fine. Your init file may be buggy, though. If MySQL terminates, then the container will terminate.

The first debug step is to look at the logs:

docker logs some-mysql

You can use this whether the container is stopped or running. Hopefully, you'll see something obvious, like you missed some semicolons.

If the logs don't help, the next thing to try is to get inside the container and see what's happening first-hand

docker run -e MYSQL_ROOT_PASSWORD=mysecretpassword -it mysql /bin/bash

This will get you a Bash shell inside your container. Then you can run

mysqld --init-file=/my-init-file.sql

And see what happens. Maybe something in your init file tells MySQL to exit cleanly, so you get no logs but the command terminates.

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

6 Comments

I edit my question. I will try your suggestion later
The command you provide with docker run does not start any shell. Is it normal?
Then maybe your dockerfile does more than you posted. When I run docker run -it mysql:latest /bin/bash, I get a shell on the mysql container.
Hi, can you confirm that this Dockerfile starts the mysqld daemon? github.com/docker-library/mysql/blob/…
Can execute this command docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql for confirmation?
|
0

Dmitri, after you made docker run with -d argument your container detached and already working as daemon if only CMD command not returned exit code.

You can check running containers by docker ps command. You can check all containers by running docker ps -a.

Also i think you will need to open mysql port outside the container. You can do it with -P argument or better way to make communication between containers is docker links.

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.