Docker
Docker is a runtime for create and manage containers.
Docker images
Images are defined by a text file call Dockerfile
.
Dockerfile Template
Docker
FROM node:lts-alpine3.14
RUN apk add --no-cache python g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
Commands
- FROM select base image. Use scratch if you want to begin with nothing.
- RUN launch a cli command.
- WORKDIR change workdir. Clean version of the command cd.
- COPY copy files inside a container. Clean version of the command copy.
- CMD latest argument of a dockerfile. This is the cli command to launch when the container start.
Docker operations
Launch a container
Start/Stop/Kill a container
See statistics about running containers
Tip for watching in direct containers status
watch docker container ps
. Very usefull when your containers constantly rebooting
Freeze / Unfreeze a container
Docker networks
Create/Delete a network
Docker storage
Check/Clean docker disk occupation
Bash
# Check
docker system df
# Clean
docker image prune
# Delete all images on my
docker rmi $(docker images -a -q)
Docker Compose
docker compose is a tool for creating multi images stack.
docker compose operations
Test a docker compose stash
Build a docker compose
Launch/Shutdown a docker compose stack
Bash
# Launch the complete docker compose
docker compose start
# Launch just a service from docker compose
docker compose start <service>
# Shutdown the complete docker compose
docker compose stop
# Shutdown just a service from docker compose
docker compose stop <service>
# Restart the complete docker compose
docker compose restart
# Restart just a service from docker compose
docker compose restart <service>
Connect to a bash inside container
Docker Compose network
To create a network beetween severals docker compose file
Tools
- Dive est un outil permettant de naviguer dans les images docker à chaque instruction et de voir les fichiers évolués.
- Portainer est un outil permettant d'obtenir une interface web pour gérer Docker et docker compose.
- Docker Bench for Security est script bash permettant de vérifier que docker est correctement installé sous linux d'un point de vue sécurité