Docker Community Forums

Share and learn in the Docker community.

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

docker

(Emiatej9) #1

Hello.

I’m newbie here and have got a problem with launching mysql container.

I runed 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.

$ 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,

Please help me.

Thanks


(Sam) #2

the options (-p) have to be BEFORE the image name

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