Internet resources
https://docs.docker.com/get-started/
https://docs.docker.com/engine/reference/builder/
Official containers:
https://hub.docker.com/search?q=&type=image&image_filter=official
Installation
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo systemctl enable docker
Images and Containers
Images are not yet running containers including one application and the os fundamentals for it.
Containers are running or sleeping instances of applications that are enclosed by the container.
Setting up images
Create directory wherever you want. Copy config files for the service to the directory. cd to that directory
Create Dockerfile in the dir. Example File for Samba container:
Build image:
docker build -t <<repository>>/<<tag>>
.
repository may be somethin like a name that explaines the containers purpose (samba_debian) the tag my be a version
Managing images
Show images on host:
docker images
Remove image (get id with command above):
docker image rm <<Image ID>>
Get official image and keep it locally (for images that you use often). E.g. debian:
docker pull debian
Managing containers
Start container (text from docs.docker.com):
Run the following command to start a container based on your new image:
docker run --publish 8000:8080 --detach --name <<name>><<repository>>:<<tag>>
There are a couple of common flags here:
--publish
asks Docker to forward traffic incoming on the host’s port 8000 to the container’s port 8080. Containers have their own private set of ports, so if you want to reach one from the network, you have to forward traffic to it in this way. Otherwise, firewall rules will prevent all network traffic from reaching your container, as a default security posture.--detach
asks Docker to run this container in the background.--name
specifies a name with which you can refer to your container in subsequent commands, in this casebb
.
Start container with interactive shell:
docker run -it <<repository>>:<<tag>> /bin/bash
Stop container:
docker stop <<name>>
Show all containers on host:
docker ps -a
Show running containers on host:
docker ps
Remove container:
docker rm <<container name>>