Commands
Install Docker
sudo apt install docker.io
Verify
sudo docker run hello-world
Restart policy
Dockerfile instructions
- FROM python:latest
- declare the image you are using
- ADD file.txt /folder/
- copy files from the config directory to folder inside the image
- WORKDIR /folder/
- set's the base-directory of the image
Docker-Compose
Filestructure
- docker-compose.yml
- instructions to orchestrate the containers
- folders for each container
- The files needed for that container
- ...
- Dockerfile
- Describes how this container works
Commands
build
docker-compose build
run
docker-compose up
Config
- version: '3'
- // docker-compose.yml must always start by the version-tag
- services:
- // the list of containers used in this composition
- server:
- // "server" is already the name of the first service
- build: server/
- // build the container inside the server directory
- command: python ./server.py
- // the command to run this service
- ports:
- 1234 : 1234
- // open a port of the container to the outside machine
- // outside-world port : container port
- restart: no
- client:
- build: client/
- command: python ./client.py
- network_mode: host
- // which part of the outside machine the container can access
- depends_on:
- server
- // definition launch dependencies/order
version: '3'
services:
server:
build: server/
command: python ./server.py
ports:
- 1234:1234
client:
build: client/
command: python ./client.py
network_mode: host
depends_on:
- server
References