Container
Container
Docker
docker-compose.yamlsupport${VAR-default}which mean that use default if no VAR.defaultcan be string like'string'docker-compose.yamlrelies on.envfile or shell environment
Pre-requirement
- Run
apt install docker-compose-v2to install docker, it will install key dependent packagedocker.io- It will start
docker.serviceanddocker.socketwhich in/lib/systemd/system/
- It will start
- Run
sudo usermod -aG docker $USERandnewgrp dockerto add current todockergroup - Add below file to
/etc/systemd/system/docker.service.d/http-proxy.conf[Service] Environment="HTTP_PROXY=http://your-proxy:your-port" Environment="HTTPS_PROXY=http://your-proxy:your-port" - Run
systemctl daemon-reloadthensystemctl restart dockerto make change effect
Volumes
docker-compose.yamlusevolumesfor persist data, can define a named volume in thevolumessection- Persists Data: Named volumes ensure that data written by the containers to specific paths is persisted outside the containers and remains intact across container restarts or deletions.
- Separation: By defining these volumes separately, each container can have isolated storage managed by Docker.
- Sharing Across Containers: Named volumes can be shared between containers, allowing them to read/write the same data if needed.
- Empty Name volume, when define a volume using
{}, you’re essentially creating a named volume with default settings.- Named Volume Creation: Docker Compose will create a named volume called
ollama. This named volume is managed by Docker and will be used to persist data written to it by the container. - Default Location:
- On Linux systems, Docker typically stores named volume data inside
/var/lib/docker/volumes/. Each volume has a subdirectory within this path. - On Windows or macOS, the location might vary depending on the Docker Desktop configuration, but it’s generally managed internally by Docker.
- On Linux systems, Docker typically stores named volume data inside
- Data Management: Docker handles the storage and lifecycle of this volume, ensuring data is retained across container restarts or removals.
- Named Volumes use
{}without host paths. They’re managed by Docker. - Bind Mounts include paths and are specified directly in the service’s
volumessection.
- Named Volume Creation: Docker Compose will create a named volume called
Config Override
docker compose -f docker-compose.yml -f docker-compose.dev.yml up -dcan make dev override base config
Pass build arg to Dockerfile
- Add
argsunderbuildto specify build args, AddARGin Dockerfile
Commands
cp: Copy data from/to dockercompose start/stop/up/down: up will build if have build config, start always run in detached modecompose up --build: explicitly specify build to trigger rebuildcompose down: when environment variable change
Multiple Stage Build
- Global
ARGDeclaration:- You can declare
ARGvariables globally, such that they are available in all build stages. If you declare theARGbefore anyFROMinstructions, it is accessible in all stages:ARG GLOBAL_ARG FROM node:14 AS builder RUN echo "Global ARG in first stage: $GLOBAL_ARG" FROM node:14 AS final RUN echo "Global ARG in second stage: $GLOBAL_ARG"Declaring
ARG GLOBAL_ARGoutside any specific stage makes it available for bothbuilderandfinalstages.
- You can declare
- Stage-Specific
ARGDeclaration:- If you declare
ARGafter aFROMinstruction, it only applies to the immediate stage following that declaration.FROM node:14 AS builder ARG STAGE_ARG RUN echo "Stage ARG in builder: $STAGE_ARG" FROM node:14 AS final ARG ANOTHER_STAGE_ARG RUN echo "Stage ARG in final: $ANOTHER_STAGE_ARG"Here,
STAGE_ARGis only available in thebuilderstage, andANOTHER_STAGE_ARGis only available in thefinalstage.
- If you declare