Dockerfile and dev / test / prod environment

I want to create a Dockerfile that can create three different images (one at the moment). These images differ only in configuration files.

I have tried:

  • creating three different docker files (does not work, because dockerfile must be named Dockerfile and be in the root context
  • find a way to pass parameters to the docker build command - did not find
  • using the ONBUILD command - I created one main file and three specific ones that copied a specific conf file to the same directory in the image (it does not work for the same reason as at the first point)
  • transferring docker file from stdin - this does not work, because then there is no context (therefore, I can not use the ADD / COPY commands)

I have to say that my ideas are running out: / How do you deal with this situation. In my opinion, this should be a common problem.

+4
source share
2 answers

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

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

You can verify that the environment variable is available using docker run -it -e mytag=abc123 ubuntu:latest env | grep mytagshowsmytag=abc123

+5
source

3 , 3 Dockerfiles. , script, docker build, .

cp Dockerfile-cfg1 Dockerfile
docker build -t "cfg1" .
cp Dockerfile-cfg2 Dockerfile
docker build -t "cfg2" .

, @user2915097, , , . , .

0

All Articles