Pass environment variables from docker-compose to container at build stage

后端 未结 1 772
耶瑟儿~
耶瑟儿~ 2020-12-25 13:55

I am trying to create configuration for several environments with a single Dockerfile, several docker-compose files and several envoronment_v

相关标签:
1条回答
  • 2020-12-25 14:29

    Your docker-compose.yml should look like this:

    version: '2'
    services:
      web:
        build:
          context: ./web
          args:
            REQUIREMENTS: "requirements_dev.txt"
    

    Your Dockerfile should define the build-argument using ARG like this:

    FROM python:3.5
    ENV PYTHONUNBUFFERED 1
    ENV APP_ROOT /usr/src/app
    ARG REQUIREMENTS
    ...
    COPY $REQUIREMENTS $APP_ROOT/
    RUN pip install -r $APP_ROOT/$REQUIREMENTS
    

    I validated this and created a minified functional demo at Github:

    https://github.com/jannikweichert/stackoverflow-41747843

    0 讨论(0)
提交回复
热议问题