skip to Main Content

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


  1. 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.

    1. List all container:
    • docker ps -a
    1. Check logs:
    • docker logs yourContainerId

    Here is my quick start command:

    docker run -d -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=root mysql:latest

    Login or Signup to reply.
  2. When you run the container, it outputs – in the log – the following message

    You need to specify one of the following as an environment variable:
    - MYSQL_ROOT_PASSWORD
    - MYSQL_ALLOW_EMPTY_PASSWORD
    - MYSQL_RANDOM_ROOT_PASSWORD
    

    Basically, MySQL won’t start without a root password or being told that no password is OK.

    Add

    ENV MYSQL_ROOT_PASSWORD=myrootpassword
    

    to your Dockerfile and it’ll run.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search