Docker Tutorial for Beginners - Techworld with Nana
This section was already familar for me from various introductory videos on the topic.
A container is made of layers of images.
Dividing a container into layers makes pulling diferent versions of the same container much faster, for example.
The difference between image and container is similar to the one between program and process.
A hosts consists of three layers:
- Applications
- Kernel
- Hardware
While VMs virtualise layers 1 and 2, Docker only virtualises 2. This results in better size, speed, but sacrifices compatibility.
docker run options:
-d: detached mode-p<host_port>:<container_port>: Binds the given host and container port--name <name>: Assigns a certain name to a container
Docker commands for debugging:
logs: See logs of a containerexec: Run a command on a container.docker exec -it <container> <shell>gives an access to the shell
Interesting example of CI, from development to deployment with various technologies.
I am not really interested the web technologies used in this example, as I am looking for a sysadmin usecase for docker, so a lot of content won't be written about.
By grouping containers with a network, data can be transfered between only with their names.
The network command is used to create, list... networks. A container can belong to a network by specifying --net on the run command.
Uses YAML to structure the run commands on a file. Docs here. Important features:
- Automatically creates a common network for all the services specified in a file.
Usage:
- Start containers (and crates network):
docker-compose -f <file> up. - Stops containers (and removes network):
docker-compose -f <file> down.
A blueprint to create docker images. Very strict and simple syntax, documentation here. Example:
FROM <base_image>
ENV <envvar_name>=<env_var_value> \
...
RUN <shell_command>
...
COPY <host_path> <container_path>
...
CMD <entrypoint_command>
Images are based on more basic images through Dockerfiles. This is called image layers
An image is created from a Dockerfile with the build command. -t specifies the tag.
This section is also not very interesting for my intended use of Docker for now, so I am skipping it.
Docker Volumes compensate the lack of persistency of the Virtual File System of the Container. A Volume is nothing more than a host file (normally a directory) mounted on the Virtual File System.
There are three type of volumes:
- Host volume: Host and container paths are specified.
- Anonymous volume: Container path is specified but the host one is automatically generated.
- Named volume: Same as anonymous but a name is given to the volume.
Volumes can be defined also in Docker Compose.
Anonymous and named volumes are stored in /var/lib/docker/volumes.