Skip to content

Instantly share code, notes, and snippets.

View DerekChia's full-sized avatar
🎯
Focusing

Derek Chia DerekChia

🎯
Focusing
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
$ docker build --no-cache -t demo-onbuild .
### REMOVED ###
Step 6/11 : RUN echo "First stage build time:"; env | grep VAR_
---> Running in 2059bd2e7860
First stage build time:
VAR_ARG=arg_value
VAR_ENV=env_value
Removing intermediate container 2059bd2e7860
---> ec2a853d2c02
# First stage
FROM debian as base
ENV VAR_ENV=env_value
ARG VAR_ARG=arg_value
ONBUILD ENV VAR_ENV_ONBUILD=onbuild_env_value
ONBUILD ARG VAR_ARG_ONBUILD=onbuild_arg_value
RUN echo "First stage build time:"; env | grep VAR_
# Second stage
FROM base
RUN echo "Second stage build time:"; env | grep VAR_
$ docker build --build-arg SOME_VAR=new-value --no-cache -t demo .
### REMOVED ###
Step 2/5 : ENV SOME_VAR=env-value
---> Running in 10d7cb325994
Removing intermediate container 10d7cb325994
---> dcab47c67952
Step 3/5 : ARG SOME_VAR=arg-value
---> Running in 265c48974673
Removing intermediate container 265c48974673
$ docker build --no-cache -t demo .
### REMOVED ###
Step 2/5 : ENV SOME_VAR=env-value
---> Running in ed8e108898e4
Removing intermediate container ed8e108898e4
---> 43da9e8e6dd6
Step 3/5 : ARG SOME_VAR=arg-value
---> Running in fb03d6097fb1
Removing intermediate container fb03d6097fb1
FROM ubuntu
ENV SOME_VAR=env-value
ARG SOME_VAR=arg-value
RUN echo "Build-time: SOME_VAR is set to ${SOME_VAR:-}"
CMD ["bash", "-c", "echo Run-time: SOME_VAR is set to ${SOME_VAR:-}"]
@DerekChia
DerekChia / docker-compose.yml
Created December 26, 2021 14:03
Start a container, read and print the environment variable. Defaults to ONE if VARIABLE_ONE is not overridden
version: "3"
services:
hello_world:
container_name: ubuntu
image: ubuntu:latest
command: '/bin/sh -c "echo ${VARIABLE_ONE:-ONE}"'
@DerekChia
DerekChia / docker-compose.yml
Created December 26, 2021 10:51
Start a container, read and print the environment variable passed in via "environment:"
version: "3"
services:
hello_world:
container_name: ubuntu
image: ubuntu:latest
environment:
VARIABLE_ONE: ONE
command: '/bin/sh -c "echo $$VARIABLE_ONE"'
@DerekChia
DerekChia / docker-compose.yml
Last active December 26, 2021 10:52
Start a container, read and print the environment variable stored in host system
version: "3"
services:
hello_world:
container_name: ubuntu
image: ubuntu:latest
command: '/bin/sh -c "echo $$VARIABLE_ONE"'
$ export VARIABLE_ONE=ONE