Docker Community Forums

Share and learn in the Docker community.

Dockerhub mysql install in ubuntu

I am installing mysql from docker hub.

---- code ----
sudo docker run -d -p 9876:3306 -e MYSQL_ROOT_PASSWORD=password mysql:5.6
---- /code ----

Installation went well,
In a minute, the status changes to Exited(1).
Why is it changing?
How do I keep it from changing?

Any help would be appreciated.

sudo docker pull mysql/mysql-server:5.7.
sudo docker run --name=mysqlCon -p 3306:3306 -d mysql/mysql-server:5.7.
sudo docker logs mysqlCon.
sudo docker exec -it mysqlCon mysql -uroot -p.
ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘NewPassword’;

MySQL takes several minutes to start-up the first time since it must initialize the database. I suspect it also restarts during that time which could cause some issues for Docker.

I’d recommend using -it to keep the container running and mounting a persistent volume so subsequent start-ups take a couple of seconds:

docker run \
  -it --rm --name mysql \
  -p 9876:3306 \
  --mount "src=mysqldata,target=/var/lib/mysql" \
  -e MYSQL_ROOT_PASSWORD=password \

My Docker for Web Developers book and video course describes how to create good development environments using Docker and Docker Compose. There’s a chapter about using MySQL and similar databases. Use the discount code dock30 for 30% off.