1

I define the arguments in the Dockerfile, but I want to build all my Dockerfiles uniformly through docker compose, if the argument values are passed into the Dockerfile through docker-compose build

  • my Dockerfile
... ARG ENVIRONMENT_VARIABLE RUN dotnet build path/to/my/porject.csproj -c $ENVIRONMENT_VARIABLE ... 
  • my docker-compose.yaml
... my.image: image: myimage:123 container_name: my.image build: context: ../../ dockerfile: path/to/Dockerfile args: ENVIRONMENT_VARIABLE: #{ENVIRONMENT_VARIABLE} ... 
2
  • Just pass the arguments while starting the container. During docker run IMAGE ARGS Commented Jul 11, 2021 at 10:50
  • 1
    One of the things I can see people struggle with, is distinguishing between what happens at build time and what happens at run-time. The way you've set yours up, it's impossible from the docker-compose file to see if your argument is runtime or build time. Personally I think the clearest way of doing things is doing builds outside of docker compose and only using docker compose to spin up images that are already built. Commented Jul 11, 2021 at 10:54

1 Answer 1

2

When you use docker compose you can pass arguments like this.

docker-compose build --build-arg ENVIRONMENT_VARIABLE=YOUR_VALUE 

Is that what You mean with Your question?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.