Last active
August 10, 2021 14:38
-
-
Save caike/ca6d82c4b47093f3c2b9ac5403268e5f to your computer and use it in GitHub Desktop.
Learn the differences between ENVs and ARGs in Docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM alpine:latest | |
# 01- ENV set directly in Dockerfile. | |
# Available during BUILDTIME and RUNTIME. | |
ENV LOCAL_ENV="hi I am LOCAL_ENV" | |
RUN echo $LOCAL_ENV | |
# 02 - ARG sent via command (docker or docker-compose) | |
# Available during BUILDTIME only. | |
ARG BUILDTIME_ENV | |
RUN echo $BUILDTIME_ENV | |
COPY script.sh ./script.sh | |
CMD ./script.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "2" | |
services: | |
app: | |
build: | |
context: . | |
dockerfile: Dockerfile | |
# 03 - ARG injected into _building_ container. | |
# Available during BUILDTIME only. | |
args: | |
- BUILDTIME_ENV="I am buildtime env" | |
environment: | |
# 04 - ENV Injected into _running_ container. | |
# Available during RUNTIME only. | |
- RUNTIME_ENV="I am runtime env" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ash | |
echo $LOCAL_ENV $BUILDTIME_ENV $RUNTIME_ENV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use the following commands to build and run:
is the same as
and finally