Introduction
This document summarizes command options and properties of compose.yaml.
◯ Overview
1. Flow of Passing Environment Variables
2. Options and Properties
There was some confusion due to the presence or absence of command option names and compose.yaml property names...
-
dockercommand- When building a Docker image
-
docker image buildcommand- Key-value format
-
--build-argoption
-
- File format
- None
- Key-value format
-
- When running a Docker container
-
docker container runcommand- Key-value format
-
--env,-eoption
-
- File format
-
--env-fileoption
-
- Key-value format
-
- When building a Docker image
-
compose.yamlfile- When building a Docker image
-
services.<service>.buildproperty- Key-value format
-
argsproperty
-
- File format
- None
- Key-value format
-
- When running a Docker container
-
services.<service>property- Key-value format
-
environmentproperty
-
- File format
-
env_fileproperty
-
- Key-value format
-
- When building a Docker image
-
docker composecommand- When building a Docker image
-
docker compose buildcommand- Key-value format
-
--build-argoption
-
- File format
-
--env-fileoption
-
- Key-value format
-
- When running a Docker container
-
docker compose upcommand- Key-value format
- None
- File format
-
--env-fileoption
-
- Key-value format
-
- When building a Docker image
◯ Sample Code
Directory names correspond to chapters
gh repo clone domodomodomo/docker-env-sample
cd docker-env-sample/part2/111
# for Bash - macOS, Ubuntu
bash cmd.sh
# for PowerShell - Windows
powershell ./cmd.ps1
1. docker command
1.1. When building a Docker image
docker image build command
1.1.1. Key-value format
docker image build \
--build-arg BLUE=Squirtle \
--build-arg RED=Charmander \
--build-arg GREEN=Bulbasaur \
.
1.1.2. File format
Not found.
- Pages checked
1.2. When running a Docker container
docker container run command
1.2.1. Key-Value Format
docker container run \
--env BLUE=Squirtle \
--env RED=Charmander \
--env GREEN=Bulbasaur \
app
1.2.2. File Format
--env-file option
docker container run \
--env-file .env.1 \
--env-file .env.2 \
--env-file .env.3 \
app
2. compose.yaml File
2.1. When building a Docker image
services.<service>.build Property
2.1.1. Key-Value Format
args Property
# Map Syntax
services:
app:
build:
context: .
args:
BLUE: Squirtle
RED: Charmander
GREEN: Bulbasaur
# Array Syntax
services:
app:
build:
context: .
args:
- BLUE=Squirtle
- RED=Charmander
- GREEN=Bulbasaur
2.1.2. File Format
Not found.
- Checked Pages
2.2. When running a Docker container
services.<service> Property
2.2.1. Key-Value Format
environment Property
# Map Syntax
services:
app:
build:
context: .
environment:
BLUE: Squirtle
RED: Charmander
GREEN: Bulbasaur
# Array Syntax
services:
app:
build:
context: .
environment:
- BLUE=Squirtle
- RED=Charmander
- GREEN=Bulbasaur
2.2.2. File Format
services:
app:
build:
context: .
env_file:
- .env.1
- .env.2
- .env.3
3. docker compose Command
3.1. When building a Docker image
docker compose build Command
3.1.1. Key-Value Format
--build-arg Option
docker compose build \
--build-arg BLUE="Squirtle" \
--build-arg RED="Charmander" \
--build-arg GREEN="Bulbasaur"
3.1.2. File Format
--env-file Option
docker compose \
--env-file .env.1 \
--env-file .env.2 \
--env-file .env.3 \
build
◯ good to know
Separating --env-file and --build-arg by the command they belong to can help understand the Docker command format more easily.
docker --log-level debug \
compose --env-file .env \
build --build-arg BLUE="Squirtle"
command command-option \
subcommand subcommand-option \
subsubcommand subsubcommand-option
-
--log-levelis an option for thedockercommand* -
--env-fileis an option for thedocker composesubcommand* -
--build-argis an option for thedocker compose buildsub-subcommand*
3.2. When running a Docker container
docker compose up Command
3.2.1. Key-Value Format
Not found.
- Checked Pages
3.2.2. File Format
docker compose \
--env-file .env.1 \
--env-file .env.2 \
--env-file .env.3 \
up
Conclusion
Thank you.


Top comments (0)