Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

docker - Dockerfile and dev/test/prod environment

I want to create Dockerfile that will be able to build three different images (one at the moment). Those images differs only in configuration files.

I was trying:

  • creating three different docker files (doesn't work because dockerfile needs to be named Dockerfile and be in context root
  • finding a way of passing parameters to docker build command - didn't find
  • using ONBUILD command - I created one main file and three specific ones which were copying specific conf file into same directory in image (it doesn't work because of the same reason as in first point)
  • passing docker file from stdin - it doesn't work because there is no context then (so I can't use ADD/COPY commands then)

I must say I run out of ideas:/ How do you handle that situation. In my opinion it should be a common issue.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Why not copy in your Dockerfile all 3 config files, and then docker run -e config=file1 (or file2 or file3) and use the value of config environment variable to get the required config file .Check the doc http://docs.docker.com/reference/commandline/cli/#run

You can also use the --env-file=[] Read in a line delimited file of environment variables of the docker run command.

You can check that environment variable is available with docker run -it -e mytag=abc123 ubuntu:latest env | grep mytag shows mytag=abc123


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...