3

In docker-compose there is a .env file which can hold all the properties of used in docker-compose.yml

Is there an equivalent of that in docker run command? I have exhausted the docs and forums but couldn't find any answers.

Here is what I am looking for: Rather than docker run -v /dir1:/dir1 -v /dir2:dir2 -p 80:80 repo/image

run docker run -config config.yml repo/image' with config.yml file holding all the property mappings

2
  • 1
    Docker has no support for this. That is what Compose is for, simplifying this process of running containers with many parameters. However, you can write a simple script that does what you want. Commented Jan 12, 2017 at 17:36
  • 1
    Just re-iterating that compose is exactly this. Commented Jan 12, 2017 at 18:48

3 Answers 3

3

One option could be to have the parameters stored in a file and just get the string of the file using cat:

docker run $(cat config.file) repo/image 

Where config.file content should be something like:

-v /dir1:/dir1 -v /dir2:dir2 -p 80:80 
Sign up to request clarification or add additional context in comments.

Comments

0

This does seem to be an unfortunate gap. The best workaround I've found is to use docker-compose with a docker-compose.yml file to define the container and all it's flags and then use

docker-compose run your-service-name-here 

To just run a single one-off container.

Comments

-1

Unfortunatelly, it is no way to do this as you describe. However you can add several env config files and merge them to one .env like describe this answer

$ awk -F= '!a[$1]++' first.env second.env > .env 

1 Comment

I think the original question was asking for properties that aren't env variables, like setting up volume bindings?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.