Overview#

This page is an overview of Docker’s main features and entities. So you can easily get familiar with what Docker is in general.

Instalation and configuration#

  1. Docker instalation USE ONLY COMMANDS PROVIDED BY DOCKER DOCUMENTATION.

  2. May be useful after installing.

    • How not to always put sudo before the docker command.

    • Something still incomprehensible.

  3. Start daemon sudo systemctl start docker.

  4. Docker cource by karpovcources.

Images#

Image is a template that is used for creating docker containers. Checkout more on specific section.

List available images.

docker images
REPOSITORY                    TAG       IMAGE ID       CREATED        SIZE
fastapi_experiment            latest    319ed841174c   7 days ago     1.04GB
httpd                         latest    c0c20df5e7be   10 days ago    148MB
python                        3.11      e9a675734068   2 weeks ago    1.01GB
alpine                        latest    a606584aa9aa   3 weeks ago    7.8MB
wine_image                    latest    70b93dd1b320   5 weeks ago    3.72GB
localhost:5001/wine_image     latest    70b93dd1b320   5 weeks ago    3.72GB
ghcr.io/mlflow/mlflow         latest    ed826ca3d0c7   5 weeks ago    793MB
ubuntu                        20.04     5f5250218d28   5 weeks ago    72.8MB
gcr.io/k8s-minikube/kicbase   v0.0.44   5a6e59a9bdc0   2 months ago   1.26GB
registry                      latest    d6b2c32a0f14   9 months ago   25.4MB

Pull image from dockerhub

There is a special resource where really free to use docker images are stored - dockerhub. Using the docker pull command, you can load any image you like.

The following cell shows process of pulling hello-world docker image and then show that it was added to the list of available docker images.

echo "=====image pulling====="
docker pull hello-world
echo "=====image displaying====="
docker images | grep hello
=====image pulling=====
Using default tag: latest
latest: Pulling from library/hello-world

Digest: sha256:1408fec50309afee38f3535383f5b09419e6dc0925bc69891e79d84cc4cdcec6
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
=====image displaying=====
hello-world                   latest    d2c94e258dcb   14 months ago   13.3kB

Remove image

You can use the docker rmi command to remove any image you don’t want in your image store. The following cell shows the process of removing the docker image we created in the previous example.

docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:1408fec50309afee38f3535383f5b09419e6dc0925bc69891e79d84cc4cdcec6
Deleted: sha256:d2c94e258dcb3c5ac2798d32e1249e42ef01cba4841c2234249495f87264ac5a
Deleted: sha256:ac28800ec8bb38d5c35b49d45a6ac4777544941199075dff8c4eb63e093aa81e

Containers#

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.

Run container

You must use the docker run command.

In the following example we have created a Ubuntu container. Later, we’ll show you that it’s a fully functional Ubuntu instance that just runs on your computer - later we’ll show it.

Some additional options are used here:

  • itd allows the container not to stop immediately after starting.

  • name allows you to specify the name of the container.

docker run -itd --name show_ubuntu ubuntu:20.04
f693d0227db3a19ee63a14e0cda7a5970c97c8a80d90a14e5d50eb63046235de

List containers

docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED         STATUS         PORTS     NAMES
f693d0227db3   ubuntu:20.04   "/bin/bash"   4 seconds ago   Up 3 seconds             show_ubuntu

The result is the docker container we created in the previous cell.

Stop container

You can stop a docker container with the docker stop command. This will stop execution of the container, but not delete it, so you can reload it later.

The following cell applies a docekr stop to the container we have just created.

docker stop show_ubuntu

echo "=====docker ps====="
docker ps
echo "=====docker ps -a====="
docker ps -a
show_ubuntu
=====docker ps=====
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
=====docker ps -a=====
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS                                PORTS     NAMES
f693d0227db3   ubuntu:20.04   "/bin/bash"   21 seconds ago   Exited (137) Less than a second ago             show_ubuntu

As you can see, it’s not listed in the docker ps output - by default it only prints active running containers. But you can still see containers in the docker ps -a command - which prints all available images.

Remove container

You can kill the container and everything associated with it using the docker rm command.

In the foolowing cell we applied docker rm to the container we used as the example for this section, and then printed docker ps -a.

docker rm show_ubuntu
docker ps -a
Error response from daemon: No such container: show_ubuntu
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

As a result, we can’t see the sample container - it has been completely deleted from the system.

Volumes#

Volume is place at the computer storage that can be counted to the docker container - so they share that memory any change.

Find out more in the specific page.

Create volume To create new volueme you have to use command docker volume create.

docker volume create temp_volume
temp_volume

List volumes to list all volumes in system use command docker volume ls.

docker volume ls
DRIVER    VOLUME NAME
local     temp_volume

Remove volume to remove created volume use command docker volume rm <volume name>.

docker volume rm temp_volume
temp_volume

Networks#

Networks in Docker allow communication between containers.

List awailable networks

docker network ls
NETWORK ID     NAME              DRIVER    SCOPE
e677bc8beaed   ansible_example   bridge    local
5390a24fd218   bridge            bridge    local
37741ce59a7f   host              host      local
1a4652d7c977   minikube          bridge    local
969663d04b2d   none              null      local

Create network

To create a network, you can use the docker network create <container_name> command. The following example creates a network named temp_network and shows it in the docker network list.

docker network create temp_network
docker network ls
060e2d8778111dd202dfa13652b3d41dd7e012416b97c72ddcb92616caed9c76
NETWORK ID     NAME           DRIVER    SCOPE
5390a24fd218   bridge         bridge    local
37741ce59a7f   host           host      local
1a4652d7c977   minikube       bridge    local
969663d04b2d   none           null      local
060e2d877811   temp_network   bridge    local

Remove network

The following cell deletes the network we’ve created before and shows the list of networks to make sure that the network temp_network has been deleted.

docker network rm temp_network
docker network ls
temp_network
NETWORK ID     NAME       DRIVER    SCOPE
5390a24fd218   bridge     bridge    local
37741ce59a7f   host       host      local
1a4652d7c977   minikube   bridge    local
969663d04b2d   none       null      local

Docker in docker#

It is typical for this resource to show some examples on clean `docker’. It’s convenient to use docker in docker to demonstrate such cases. The following cell shows docker in docker dockerfile, which is used for such cases. It installs tools that allow you to run bash code in Jupyter. You can connect to it (e.g. using vscode dev container extension) and use it as a regular docker.

cat overview_files/dockerfile
FROM docker:dind

RUN apk update && apk add bash python3-dev py-pip gcc musl-dev linux-headers
RUN pip3 install --break-system-packages bash_kernel && python -m bash_kernel.install

To build it use:

docker build -t knowledge_docker ./overview_files/ &> /dev/null

And from the root direcotry of the repo with:

docker run -itd --privileged --rm --name knowledge_docker -v ./:/knowledge knowledge_docker &> /dev/null