I have to start a mysql container through a dockerfile, in which I simply have to set the environment variables, I wrote the dockerfile like this, but when I do the "docker run" it remains in exited state.
FROM mysql
ENV DB_HOST=localhost
ENV DB_NAME=productsdb
ENV DB_USER=root
ENV DB_PWD=mm22
ENV DB_DIALECT=mysql
ENV SERVER_PORT=5000
ENV DB_PORT=3306
2
Answers
If there is no error in your container add option -d to run container background.
docker run -d yourMysqlImage:yourTag
If you didn’t build image yet.
docker build -f yourDockerfile
And you should check container logs to see what happend.
docker ps -a
docker logs yourContainerId
Here is my quick start command:
docker run -d -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=root mysql:latest
When you run the container, it outputs – in the log – the following message
Basically, MySQL won’t start without a root password or being told that no password is OK.
Add
to your Dockerfile and it’ll run.