Image vs container
- Docker image: is a template, a blueprint of a filesystem with application and dependencies installed. It is read-only.
- Docker container: is a running instance of a docker image. It is a lightweight, isolated
Quick commands
# List docker images
docker images
# List running containers
docker container ps
# Run container.
mkdir -p ./storage/openwritings.net
docker run -p 9000:8080 --user root:root -v ./storage/openwritings.net:/storage dokuwiki/dokuwiki:stable
# Open with your browser: http://localhost:9000/install.php
# See how docker was build, dockerfile.
docker image history --no-trunc <IMAGE ID>
# Get in the shell of the container.
docker exec -it fin-D8.9.20 sh
docker container run -it <CONTAINER> sh
# Execute commands in shell: https://docs.docker.com/reference/cli/docker/container/exec/#description
docker exec -it my_container sh -c "echo a && echo b"
# Run container and execute commands
docker run -it <IMAGE ID> /bin/sh -c "cd /app; du -ch -d 1"
Build docker
# Dockerfile
FROM amd64/alpine:3.14
CMD ["date"]
# Build Dockerfile with name=hello-date, tag=latest.
docker build --tag hello-date:latest .
docker build --tag hello-date:latest -f Dockerfile .
# Run container created from image, hello-date.
docker run hello-date
# Run it and get in the shell
docker run -it hello-date /bin/sh
Cleanup
# Delete dangling images
docker rmi $(docker images -f "dangling=true" -q) || true
# To clean the docker environment, removing all the containers and images. Free spaces.
docker system prune -a