Skip to content

docker

installation 2023

This page worked completely : see

But in even shorter terms

sudo su 
apt update
apt install apt-transport-https ca-certificates curl gnupg lsb-release -y
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update
apt -y install docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl status docker

Now you probably can run as root, but as a user you will get an error, so:

usermod -aG docker kees

This will still not work, the id is not yet in effect :

id # you will see no 'docker' group yet
uid=1000(kees) gid=1000(kees) groups=1000(kees),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),108(netdev),113(bluetooth),117(lpadmin),120(scanner),127(vboxusers)
kees@tool:/work/utilburg/11160$ docker run hello-world
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create": dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.

The easiest way to get it running without logging out and in again is :

su kees
 id
uid=1000(kees) gid=1000(kees) groups=1000(kees),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),108(netdev),113(bluetooth),117(lpadmin),120(scanner),127(vboxusers),998(docker)
docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

... 

Notice that it still is advisable to 'Logout kees' and re-enter X because then all you new terminals will have group 'docker' added.

basic usage

hello world example
1
2
3
docker image ls 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        8 months ago        1.84kB

hello-world is a one shot program, it will run much faster the second time because it is already downloaded. An image is a harddisk file, a container is in running memory. So since hello-world exits after running you won't see it in image ls unless you use --all

list containers
1
2
3
4
5
6
docker container ls 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
docker container ls --all
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
4d2c4ab60731        hello-world         "/hello"            13 minutes ago      Exited (0) 12 minutes ago                       agitated_kalam
35fa28f807df        hello-world         "/hello"            14 minutes ago      Exited (0) 14 minutes ago                       mystifying_chaum

Why twice ? Because i ran it twice ! By the way this seems to be a shorter version of this command :

running containers
docker ps -a

image creation

To create an image you need a base to start with. Since we want to test it standalone, just download it :

create images
docker pull debian # debian 10.1 (sep 2019) so up-to-date
docker run -it debian # this is needed to start a bash session 

Now docker ps will show something because a container is running:

running containers
1
2
3
 docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED          STATUS          PORTS     NAMES
28f6566889d4   debian    "bash"    23 seconds ago   Up 22 seconds             hardcore_wozniak

So now you can look around in this container and try out commands to put in a Dockerfile. Note that it is a very small (slim) version, uname for instance will work but lsb_release won't.

uname -a 
Linux 28f6566889d4 5.10.0-21-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21) x86_64 GNU/Linux
apt list | wc
     97     385    4846
if you tried this command on a fairly fresh installed debian

apt list | wc
   58766  178584 2492138

slightly larger ;)

filling a docker image

As an example i will try to install cheatsheet in a docker debian image. Let's start with this Dockerfile :

Dockerfile
1
2
3
4
5
6
7
FROM debian:latest
MAINTAINER klopt.org
RUN apt-get update
RUN apt-get -y install apache2
COPY index.html /var/www/html/
CMD [“/usr/sbin/apache2ctl start”, “-D”, “FOREGROUND”]
EXPOSE 80

It uses the same debian image already downloaded, and then installs apache and (tries to) run it with a simple index.html which you must provide in the current directory. ("hello" will suffice).

However, the build command goes ok :

run build
docker build --tag=cheat_sheet
Sending build context to Docker daemon  3.072kB
Step 1/7 : FROM debian:latest
 ---> c2c03a296d23
Step 2/7 : MAINTAINER klopt.org
 ---> Using cache
 ---> 7018bc606f48
Step 3/7 : RUN apt-get update
 ---> Using cache
 ---> 9066b28e09f8
Step 4/7 : RUN apt-get -y install apache2
 ---> Using cache
 ---> fa214f511faf
Step 5/7 : COPY index.html /var/www/html/
 ---> Using cache
 ---> 2e54af186b5a
Step 6/7 : CMD [“/usr/sbin/apache2ctl start”, “-D”, “FOREGROUND”]
 ---> Using cache
 ---> 2ab06e165030
Step 7/7 : EXPOSE 80
 ---> Using cache
 ---> 1f35574f73d0
Successfully built 1f35574f73d0
Successfully tagged cheat_sheet:latest

This is a second run, so much of the apt-get commands are a lot quieter. However running it fails :

run and delete afterwards
docker run --rm cheat_sheet
/bin/sh: 1: [“/usr/sbin/apache2ctl: not found

To debug this, we need to log in to the image, but this error prevents that.