Hongmin Yang
Hongmin Yang

Reputation: 81

Docker, Runned mysql container with port forwarding is stopped immediately as soon as it launched

I have got a problem with launching MySQL container.

I run MySQL container with below command:

$ sudo docker run -d --name stockdb -e MYSQL_ROOT_PASSWORD=yang1234 -e MYSQL_DATABASE=stkanalysis mysql:5.7 -p 3307:3306

and checked result using

$ sudo docker ps -a

This is the result.

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 34e98ad90f73 mysql:5.7 “docker-entrypoint…” 2 seconds ago Exited (1) 1 second ago stockdb

When I launched same MySQL container without option -p, it worked well like this:

$ sudo docker run -d --name stockdb -e MYSQL_ROOT_PASSWORD=yang1234 -e MYSQL_DATABASE=stkanalysis mysql:5.7

But, whenever I put the port forwarding option -p, running container is failed(technically, it is exited as soon as runed)

I hope to run MySQL container with port forwarding to connect its DBMS from outside host.

I’m using Ubuntu 16.04 and Docker version is 17.09.0-ce.

Upvotes: 0

Views: 5077

Answers (1)

Hongmin Yang
Hongmin Yang

Reputation: 81

I solved my problem.

The cause was the position of option -p located at the end of commend.

I moved option -p statement forward, and it works well now.

$ sudo docker run --name stockdb -p 3307:3306 -p 3308:22 -e MYSQL_ROOT_PASSWORD=yang1234 -e MYSQL_DATABASE=stkanalysis mysql:5.7

thank you.

Upvotes: 1

Related Questions