This tutorial is good for starting with docker on rockylinux-9
Install docker repo as root with priority=50
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo dnf install docker-ce docker-ce-cli containerd.io systemctl start docker systemctl status docker systemctl enable docker
Add your username to docker group
usermod -aG docker $USER
Download and install hub-tool
cd /tmp wget https://github.com/docker/hub-tool/releases/download/v0.4.6/hub-tool-linux-amd64.tar.gz tar -xvf hub-tool-linux-amd64.tar.gz mv hub-tool hub-tool-v0.4.6 mv /tmp/hub-tool-v0.4.6 /opt chown -Rv root:root /opt/hub-tool-v0.4.6 chcon -u system_u -t usr_t -Rv /opt/hub-tool-v0.4.6
Add hub-tool to your PATH
emacs ~/.bashrc.d/bash_aliases export PATH=/opt/hub-tool-v0.4.6:$PATH
Docker has a good help online
docker docker search --help
Per default you don't have any local images
docker images REPOSITORY TAG IMAGE ID CREATED SIZE
Run the docker "Hello World" example
docker run hello-world
Show docker disk usage
docker system df
Search for RockyLinux images on Docker Hub
docker search rockylinux
Setup hub-tool with a docker account
hub-tool --version hub-tool login user=* pass=*
List all tags of rockylinux/rockylinux
hub-tool tag ls --sort updated rockylinux/rockylinux TAG DIGEST STATUS LAST UPDATE LAST PUSHED LAST PULLED SIZE rockylinux/rockylinux:9-minimal sha256:9e67a934b74b8fe2ef9d... active 2 months ago 2 months 22 minutes 241.4MB rockylinux/rockylinux:9.5 sha256:531a9a14d0e640d32f61... active 2 months ago 2 months 51 seconds 348.7MB rockylinux/rockylinux:8 sha256:f514765516176a9aa472... active 8 months ago 8 months About a minute 151.8MB rockylinux/rockylinux:8.10-minimal sha256:55ddcbe11a7bf1696f67... active 8 months ago 8 months 7 minutes 76.57MB rockylinux/rockylinux:8.10 sha256:f514765516176a9aa472... active 8 months ago 8 months About a minute 151.8MB
Download an image
docker pull rockylinux/rockylinux:9.5
A second pull will check if a download is really necessary
docker pull rockylinux/rockylinux:9.5 9.5: Pulling from rockylinux/rockylinux Digest: sha256:149fd31d916038eb1084d0e051537e279d7afcd5de0b365254e8fa3c3ef12bad Status: Image is up to date for rockylinux/rockylinux:9.5 docker.io/rockylinux/rockylinux:9.5
Create a new container and install some packages
docker run -it rockylinux/rockylinux:9.5 [root@c779d77f7557 /]# dnf install epel-release dnf install htop ncurses file vim-minmal exit
Create an image from container c779d77f7557
docker commit -m "generic container" -a "Mihai Vasilian" c779d77f7557 mihai-repo/rocky-9
List local images
docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE mihai-repo/rocky-9 latest aa5326bfb9df 2 minutes ago 344MB hello-world latest 74cc54e27dc4 2 weeks ago 10.1kB rockylinux/rockylinux 9.5 bb8a97547d22 2 months ago 234MB
List local containers
docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c54574f205f8 hello-world "/hello" 11 minutes ago Exited (0) 11 minutes ago festive_mirzakhani c779d77f7557 rockylinux/rockylinux:9.5 "/bin/bash" 26 minutes ago Exited (137) 6 minutes ago busy_hamilton
How to use container c779d77f7557
docker start c779d77f7557 : start in detached mode docker stop c779d77f7557 : stop a container docker restart c779d77f7557 : restart in detached mode docker exec -it c779d77f7557 bash : execute a command in a running container
Remove container c54574f205f8 (hello-world)
docker rm c54574f205f8
Remove image 74cc54e27dc4 (hello-world)
docker rmi 74cc54e27dc4 Untagged: hello-world:latest Untagged: hello-world@sha256:d715f14f9eca81473d9112df50457893aa4d099adeb4729f679006bf5ea12407 Deleted: sha256:74cc54e27dc41bb10dc4b2226072d469509f2f22f1a3ce74f4a59661a1d44602 Deleted: sha256:63a41026379f4391a306242eb0b9f26dc3550d863b7fdbb97d899f6eb89efe72
Miscellaneous.
Let's look at docker run command.
docker help run Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
This command doesn't do anything. No container is created, or if it is created is destroyed immediately.
docker run bb8a97547d22 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Another command that is not very useful. The container is destroyed after ls finishes.
docker run bb8a97547d22 ls -l / total 56 dr-xr-xr-x. 2 root root 4096 Nov 3 2024 afs lrwxrwxrwx. 1 root root 7 Nov 3 2024 bin -> usr/bin dr-xr-xr-x. 2 root root 4096 Nov 3 2024 boot drwxr-xr-x. 5 root root 340 Jul 16 17:58 dev drwxrwxr-x. 1 root root 4096 Jul 16 17:58 etc drwxr-xr-x. 2 root root 4096 Nov 3 2024 home lrwxrwxrwx. 1 root root 7 Nov 3 2024 lib -> usr/lib lrwxrwxrwx. 1 root root 9 Nov 3 2024 lib64 -> usr/lib64 drwxr-xr-x. 2 root root 4096 Nov 3 2024 media drwxr-xr-x. 2 root root 4096 Nov 3 2024 mnt drwxr-xr-x. 2 root root 4096 Nov 3 2024 opt dr-xr-xr-x. 1234 root root 0 Jul 16 17:58 proc dr-xr-x---. 2 root root 4096 Nov 18 2024 root drwxr-xr-x. 2 root root 4096 Nov 18 2024 run lrwxrwxrwx. 1 root root 8 Nov 3 2024 sbin -> usr/sbin drwxr-xr-x. 2 root root 4096 Nov 3 2024 srv dr-xr-xr-x. 13 root root 0 Jul 16 11:48 sys drwxrwxrwt. 2 root root 4096 Nov 3 2024 tmp drwxr-xr-x. 12 root root 4096 Nov 18 2024 usr drwxr-xr-x. 18 root root 4096 Nov 18 2024 var mihai@rocky-9: ~$ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Create the container -i, --interactive
docker run -i bb8a97547d22 (the command does not return, you need to open another terminal and get in the container)
Create the container with a terminal -t, --tty attached. Must have -i to allow the output in the terminal.
docker run -it bb8a97547d22 [root@61bb06b308e8 /]# exit exit mihai@rocky-9: ~$ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Create the container and bind mount a directory from the host in the container:
docker run --mount type=bind,src=/home/mihai/Downloads/Mastering_UNIX_SS,dst=/mnt/Mastering_UNIX-SS -it bb8a97547d22 [root@898f104efafc /]# ls -l /mnt total 4 drwxr-xr-x. 3 1000 1000 4096 Jan 22 18:05 Mastering_UNIX-SS