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:
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 | |
|---|---|
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
Why twice ? Because i ran it twice ! By the way this seems to be a shorter version of this command :
| running containers | |
|---|---|
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 | |
|---|---|
Now docker ps will show something because a container is running:
| running containers | |
|---|---|
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
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 | |
|---|---|
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 :
This is a second run, so much of the apt-get commands are a lot quieter. However running it fails :
| run and delete afterwards | |
|---|---|
To debug this, we need to log in to the image, but this error prevents that.