Introductie tot Docker
Tim Sangster
Software Engineer @ DataCamp
Variabelen maken in een Dockerfile
ARG <var_name>=<var_value>
Bijv. ARG path=/home/repl
Gebruiken in de Dockerfile
$path
Bijv. COPY /local/path $path
De Python-versie instellen
FROM ubuntu
ARG python_version=3.9.7-1+bionic1
RUN apt-get install python3=$python_version
RUN apt-get install python3-dev=$python_version
Een map configureren
FROM ubuntu
ARG project_folder=/projects/pipeline_v3
COPY /local/project/files $project_folder
COPY /local/project/test_files $project_folder/tests
FROM ubuntu
ARG project_folder=/projects/pipeline_v3
COPY /local/project/files $project_folder
COPY /local/project/test_files $project_folder/tests
Een variabele zetten in de build-opdracht
docker build --build-arg project_folder=/repl/pipeline .
ARG wordt overschreven en bestanden komen in:
COPY /local/project/files /repl/pipeline
COPY /local/project/test_files /repl/pipeline/tests
Variabelen maken in een Dockerfile
ENV <var_name>=<var_value>
Bijv. ENV DB_USER=pipeline_user
Gebruiken in de Dockerfile of runtime
$DB_USER
Bijv. CMD psql -U $DB_USER
Een directory instellen voor runtime
ENV DATA_DIR=/usr/local/var/postgres
ENV MODE production
Een variabele instellen of vervangen bij runtime
docker run --env <key>=<value> <image-name>
docker run --env POSTGRES_USER=test_db --env POSTGRES_PASSWORD=test_db postgres
docker history <image-name>
ARG DB_PASSWORD=example_password
Wordt getoond in docker history:
IMAGE CREATED CREATED BY SIZE ...
cd338027297f 2 months ago ARG DB_PASSWORD=example_password 0B ...
| Gebruik | Dockerfile-instructie |
|---|---|
| Variabele alleen tijdens build | ARG <name>=<value> |
| Variabele maken | ENV <name>=<value> |
| Gebruik | Shell-opdracht |
|---|---|
| ARG overschrijven in docker build | docker build --build-arg <name>=<value> |
| ENV overschrijven in docker run | docker run --env <name>=<value> <image-name> |
| Instructies zien voor een image | docker history <image-name> |
Introductie tot Docker