Dockerfile and dev/test/prod environment

后端 未结 3 1279
情歌与酒
情歌与酒 2020-12-17 04:05

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: <

相关标签:
3条回答
  • 2020-12-17 04:38

    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

    0 讨论(0)
  • 2020-12-17 04:47

    If you want 3 different images, use 3 different Dockerfiles. The naming issue is annoying, but you can write a helper script that simply copies files and calls docker build e.g.

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

    However, as @user2915097 suggests, a better solution is probably to have a single image and choose the config at run-time. This means less overhead of looking after and maintaining multiple images.

    0 讨论(0)
  • 2020-12-17 04:59

    I have added three different files:

    test.Dockerfile
    dev.Dockerfile
    prod.Dockerfile
    

    and I have run them using the file name:

    docker build -t name/name -f test.Dockerfile .
    docker build -t name/name -f dev.Dockerfile .
    docker build -t name/name -f prod.Dockerfile .
    
    0 讨论(0)
提交回复
热议问题