docker / compose

Define and run multi-container applications with Docker
https://docs.docker.com/compose/
Apache License 2.0
33.98k stars 5.23k forks source link

Proposal: support for args_file #2545

Closed mbontemps closed 1 year ago

mbontemps commented 8 years ago

Motivation for this proposal

Introduce a args_file: section working the same way that env_file: works - but in the build phase.

Proposed documentation

args_file

Add build arguments from a file. Can be a single value or a list.

If you have specified a Compose file with docker-compose -f FILE, paths in args_file are relative to the directory that file is in.

Environment variables specified in args override these values.

build:
 args_file: .args

build:
  args_file:
    - ./common.env
    - ./apps/web.env
    - /opt/secrets.env

Compose expects each line in an env file to be in VAR=VAL format. Lines beginning with # (i.e. comments) are ignored, as are blank lines.

# Set the secret token necessary to clone the dependencies
SECRET_TOKEN=yNxbjX
aanand commented 8 years ago

Makes sense to me.

marcellodesales commented 8 years ago

:+1:

thaJeztah commented 8 years ago

Nice idea

I'm not sure we should use /opt/secrets.env as an example in our documentation, given that we discourage people to use build-time args for secrets (the args are included in the history of an image, so would be visible to others)

daef commented 8 years ago

i'd really love args_file, i kinda expected it to be there - but i am disappoint now i've found it just got proposed

marcellodesales commented 8 years ago

@thaJeztah Is this planned for the next release?

schmunk42 commented 8 years ago

These tokens should however not appear in your docker-compose.yml file

A workaround is to use a .env file and ENV variables (compose 1.7+ AFAIR)

version: '2'
services:
  php:
    build:
      dockerfile: Dockerfile-7.0-fpm
      context: .
      args:
        - GITHUB_API_TOKEN=${GITHUB_API_TOKEN}
    image: local/dmstr/php-yii2
    environment:
      - GITHUB_API_TOKEN=${GITHUB_API_TOKEN}
yangm97 commented 7 years ago

@schmunk42 that workaround didn’t work for me.

schmunk42 commented 7 years ago

@yangm97 Did you try with a recent docker-compose version? Can you set build args in docker-compose (without variables)?

yangm97 commented 7 years ago

docker-compose version 1.9.0, build 2585387

Setting args on docker-compose.yml work fine.

  bot:
    build:
      args:
        - LUA=5.2 # this works
        - NATIVE=${NATIVE} # these don't
        - ROCKS=${ROCKS}
      context: .
    command: $BOT
    depends_on:
      - db
      - redis
    env_file:
      - .deps
      - .env
    environment:
      - NATIVE=${NATIVE}
      - ROCKS=${ROCKS}
      - REDIS_HOST=redis
      - DB_HOST=db
    privileged: true
    restart: always
yangm97 commented 7 years ago

So far, the only ways I got to read build time arguments from a file were:

  1. Source the args file on host and then run docker-compose with build args;
  2. Copy the args file on the Dockerfile and then source the file using the RUN command.
schmunk42 commented 7 years ago

These have to be in your .env file

NATIVE=${NATIVE}
ROCKS=${ROCKS}

Double check it with docker-compose config

bildschirmfoto 2017-02-14 um 18 36 07
yangm97 commented 7 years ago

These have to be in your .env file

I have multiple env files:

    env_file:
      - .deps
      - .env

Do I need to explicitly set these variables on .env or it should work when I set these using the .deps file?

My .deps file looks like this:

LUA=5.2

NATIVE="libreadline-dev libssl-dev lua$LUA luarocks liblua$LUA-dev curl libcurl4-gnutls-dev figlet deborphan git make unzip"
ROCKS="luasec luasocket redis-lua lua-term serpent dkjson Lua-cURL lanes luautf8”
schmunk42 commented 7 years ago

Do I need to explicitly set these variables on .env or it should work when I set these using the .deps file?

Yes, it has to be in .env - which is the default for docker-compose. I've written about this in the docs for our application framework. I won't recommend using .env as an application environment file, btw.

It's a bit confusing, because docker-compose has "hijacked" this filename, when a lot of people were already using it for applications. I'd call it "control-environment" file now.

jvitor83 commented 6 years ago

Any ETA for that?

stephan-henningsen commented 5 years ago

Add the env_file already! 4 years have passed since this was first proposed here.

ndeloof commented 5 years ago

I think it would make perfect sense if docker build had support for some --args-file option, and then compose to align with it. As compose offers option to run the build using the plain docker CLI, transposing arg_file option to the CLI would require extra efforts and potential bugs.

joshua-hester commented 3 years ago

Whats the resolution on this?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

peabnuts123 commented 3 years ago

Is there a label that can be added to this to prevent it from going stale? It's a feature request.

stale[bot] commented 3 years ago

This issue has been automatically marked as not stale anymore due to the recent activity.

maciekgrochowicz commented 2 years ago

So 5.5 years after this issue was opened: any plans to actually implement that?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

daef commented 1 year ago

⚡⚡ issue: activate! ⚡⚡

stale[bot] commented 1 year ago

This issue has been automatically marked as not stale anymore due to the recent activity.

ndeloof commented 1 year ago

As noted on https://github.com/docker/compose/issues/2545#issuecomment-543099520, this feature would only make sense if aligned with other docker commands, i.e. if docker build --args-file .. is a thing, then obviously docker compose should support this as well. For this reason, I'm closing this issue as "not planned", in a sense "not planned as a standalone docker compose feature" - if docker CLI or buildx evolves to offer this feature, we'll be happy to de the same.

daef commented 1 year ago

env-file is not aligned enough?