1

I am new with Docker. I have a small Java application that I am trying to run inside Docker. I have created a Dockerfile to build the image.

My application is reading Environment Variables to know which database to connect to.

When running the command

docker run -d -p 80:80 occm -e "MYSQL_USER=user" -e "MYSQL_PASSWORD=password" -e "MYSQL_PORT=3306" -e "MYSQL_HOST=somehost"

and then enumerating all the variables using System.getenv, I dont see any of them. So I have added to the Docker file

ENV MYSQL_HOST=localhost

now when I run the container I see this variable, but I see it with the localhost value and not somehost.

What am I doing wrong?

1 Answer 1

6

The problem is how you are running your docker image.

$ docker run --help

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

So, you are passing -e "..." -e "..." as command and arguments

You need to use -e as [OPTIONS].

$ docker run -d -p 80:80 -e "MYSQL_USER=user" -e "MYSQL_PASSWORD=password" -e "MYSQL_PORT=3306" -e "MYSQL_HOST=somehost" occm
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.