How do i pass an argument along with docker-compos

2020-05-25 06:14发布

I have a docker-compose.yml file and in the terminal I am typing docker-compose up [something] but I would also like to pass an argument to docker-compose.yml. Is this possible? I've read about interpolation variables and tried to specify a variable in the .yml file using ${testval} and then docker-compose up [something] var="test" but I receive the following error:

WARNING: The testval variable is not set. Defaulting to a blank string.
ERROR: No such service: testval=test

7条回答
闹够了就滚
2楼-- · 2020-05-25 06:57

You need to ensure 2 things:

  1. The docker-compose.yml has the environment variable declared. For example,
services:
    app:
        image: python3.7
        environment:
            - "SECRET_KEY=${SECRET_KEY}"
  1. have the variable available in the environment when docker-compose up is called:
SECRET_KEY="not a secret" docker-compose up

Note that this is not equivalent to pass them during build, as it is not advisable to store secrets in docker images.

查看更多
登录 后发表回答