RHEL - Docker

CentOS 7 - Install docker from site

# curl -fsSL https://get.docker.com/ | sh
# systemctl start docker; systemctl status docker
# systemctl enable docker

Install docker compose if needed:

# yum install -y docker-compose

EL 9 - Install docker-ce from official EL docker repo

(taken from https://www.liquidweb.com/kb/install-docker-on-linux-almalinux/)

# dnf --refresh update
# dnf upgrade
# dnf install yum-utils
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# dnf install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# systemctl start docker && systemctl enable docker && systemctl status docker
# docker version
# docker run hello-world

Add user privileges

Add user that should be able to run docker containers:

# usermod -aG docker example

Change Firewalld backend

If running on RHEL and running firewalld, make sure to change firewalld backend from nftables to iptables

Build docker image

Simple

$ docker build ./<directory_where_is_dockerfile>
...
Successfully built <ID_of_container_e.g._aaa444bbb555>

Tag the image and push to private registry:

docker tag <ID_of_the_container_e.g._aaa444bbb555> registry.gitlab.com/<project_path_e.g._group_slash_subgroup_slash_project-name>/<name><:tag>

docker push <name><:tag>

Build tagged image for registry with some param and push it to registry:

$ docker build -t registry.gitlab.com/<project_path>/<image_name> --build-arg ARG1=val1 .
...
$ docker image ls
...
$ docker push registry.gitlab.com/<project_path>/<image_name>

Remote access setup

With TLS certificates: https://quaded.com/docker-remote-access-api-setup/

With SSH: https://linuxhandbook.com/docker-remote-access/

Misc

Space usage:

https://codeopolis.com/posts/commands-to-view-docker-disk-space-usage/

Attach to running container to see stdout:

$ docker container attach image_name

CTRL+P CTRL+Q

Run shell:

$ docker container exec -it image_name /bin/sh

Utils

Install ping and telnet on ubuntu:

# apt-get update -y && apt-get install -y iputils-ping telnet