Rafael Pereira
Rafael Pereira

Reputation: 331

An image requires an environment variable to run, how to pass variable on Dockerfile

I'm trying to build a Dockerfile based on the realm/realm-object-server image. To create a container with that image, I have to run the command:

$ docker run -p 9080:9080 -e ROS_TOS_EMAIL_ADDRESS="your-email-address" realm/realm-object-server

providing an email.

My Dockerfile starts:

FROM realm/realm-object-server:latest

how can I pass the ROS_TOS_EMAIL_ADDRESS environment variable to the FROM image? Otherwise it gives me an error later when executing the realm-object-server.

Upvotes: 0

Views: 1700

Answers (2)

sayboras
sayboras

Reputation: 5165

There are multiple ways to pass env variables into docker.

  • Use ENV in Dockerfile. Refer here
  • Use -env-file option in docker run command. Refer here.
  • Use -e option in docker run command. Refer here
  • Use environment block in docker-compose

Based on your question, first one is good enough.

Upvotes: 1

Rafael Pereira
Rafael Pereira

Reputation: 331

Oh, nevermind.

An ENV ROS_TOS_EMAIL_ADDRESS="email-goes-here" after FROM works. I thought it had to be set before FROM and only ARG was possible for that, which did not set an environment variable just a variable for the Dockerfile context.

Now it works.

Upvotes: 1

Related Questions