Skip to content

Instantly share code, notes, and snippets.

@reitzig
Last active January 27, 2024 00:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reitzig/4a1cccc965b50a15868fb345d770cdec to your computer and use it in GitHub Desktop.
Save reitzig/4a1cccc965b50a15868fb345d770cdec to your computer and use it in GitHub Desktop.
MWE: docker-compose.yaml with build arguments
version: "3.9"
services:
foo:
build:
context: .
# dockerfile: Dockerfile # in case you were not using the default
args:
foo: "some foo!"
image: foo-repro
container_name: foo-repro
FROM ubuntu
ARG foo="setme"
# Available at build time:
RUN echo foo=${foo} > foo
# Need to "convert" into environment variable so it's available at runtime:
ENV FOO ${foo}
CMD [ "sh", "-c", "cat foo; echo FOO=${FOO}" ]
@reitzig
Copy link
Author

reitzig commented Feb 24, 2022

Run with

docker-compose up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment