Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
Docker packs an app with everything it needs into an image and runs it as an isolated container. The docker CLI talks to the dockerd daemon (service docker.service). Images come from registries (Docker Hub, GitHub ghcr.io, Azure ACR). Docker Compose (docker compose) runs several containers from one YAML file.
On RHEL the built-in tool is podman (same commands, no daemon, rootless by default). Docker CE is installed from Docker's own repository. Users in the docker group are root on the host — keep that group small.
Zo schrijf je het
docker COMMAND [OPTIONS] [ARGS]
docker compose [-f compose.yaml] up|down|ps|logsBelangrijkste delen
Main commands
run- Create and start a container from an image.
ps[-a]- List running (all) containers.
build-tNAME:TAG.- Build an image from a Dockerfile.
images/imagels- List local images.
pull/push- Download / upload an image.
exec-itCsh- Run a command inside a running container.
logs[-f]C- Show container output.
stop/start/restart/rmC- Container life cycle.
inspectOBJ- Show low-level JSON details.
volume/network- Manage volumes and networks.
compose- Multi-container apps from compose.yaml.
systemdf/systemprune- Disk use / clean up.
login/logoutREGISTRY- Log in to a registry.
buildx- Advanced builds (multi-platform, cache).
scout- Check images for known CVEs (Docker Scout).
Opties 15
Meest gebruikt
docker run options
Niets past bij dit filter.
Voorbeelden 11
$ als gewone gebruiker# als root (of met sudo)
1Install Docker CE on RHEL and run a test
2Run a web server in the background
docker run -d --name web -p 8080:80 --restart unless-stopped nginx:1.27 docker ps curl -I http://localhost:80803Look inside and read the logs
docker logs -f --tail 50 web docker exec -it web sh docker inspect -f '{{.NetworkSettings.IPAddress}}' web4Build and tag an image
cat Dockerfile FROM python:3.12-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . USER 1001 CMD ["python", "app.py"] docker build -t ghcr.io/s0sta/shop:1.4.0 .5Push to a registry
echo "$GHCR_TOKEN" | docker login ghcr.io -u s0sta --password-stdin docker push ghcr.io/s0sta/shop:1.4.06Run a hardened container
docker run -d --name api --read-only --tmpfs /tmp -u 1001:1001 --cap-drop ALL --security-opt no-new-privileges --memory 256m --cpus 0.5 -p 8080:8080 ghcr.io/s0sta/shop:1.4.07Keep data in a named volume
docker volume create pgdata docker run -d --name db -e POSTGRES_PASSWORD_FILE=/run/secrets/pg -v pgdata:/var/lib/postgresql/data postgres:168Run a full stack with Compose
cat compose.yaml services: web: image: ghcr.io/s0sta/shop:1.4.0 ports: ["8080:8080"] depends_on: [db] db: image: postgres:16 volumes: [pgdata:/var/lib/postgresql/data] volumes: pgdata: {} docker compose up -d docker compose ps docker compose logs -f web docker compose down9Build for two CPU types
docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/s0sta/shop:1.4.0 --push .10Check an image for CVEs
docker scout cves ghcr.io/s0sta/shop:1.4.0 trivy image ghcr.io/s0sta/shop:1.4.011Free disk space
docker system df docker system prune -a --volumes
Niets past bij dit filter.
Let op
- The
dockergroup = root on the host. Prefer rootless Docker or podman. - Never put secrets in a Dockerfile (
ENV,COPY .env): they stay in the image layers. -p 8080:80opens the port on all addresses and passes around firewalld rules; use-p 127.0.0.1:8080:80for local-only.- Pin image tags (better: digests), never use
latestin production.
Bestanden
/etc/docker/daemon.json- Daemon settings (log driver, registries, userns-remap).
/var/lib/docker/- Images, containers, volumes.
~/.docker/config.json- Registry logins.
/var/run/docker.sock- The daemon API socket (root access!).
Tips om te onthouden
- Add a
.dockerignore(with.git,.env,node_modules) to keep images small and secret-free. - Use multi-stage builds and slim or distroless base images.
Exitcodes
0 | Success. |
125 | Docker daemon error. |
126 | The command in the container cannot run. |
127 | The command in the container was not found. |