How to install and configure docker In SUSE Linux Enterprise

Docker is an open source containerization platform. It enables developers to package applications into containers—standardized executable components combining application source code with the operating system (OS) libraries and dependencies required to run that code in any environment.

Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. 

In this guide we are going to explore various options to install docker in SUSE Linux Enterprise(SLES).

Also check

Prerequisites

To install Docker Engine, you need to have the following

  • Updated SUSE Linux Enterprise(SLES) based server
  • Internet connection
  • Basic knowledge of linux terminal

Table of Content

  • Update system packages
  • Uninstall old versions
  • Installing docker
  • Starting and enabling Docker
  • Uninstalling Docker

Updating system packages

Before proceeding let’s ensure that our system is up to date. Use this command to update the system and all the packages

sudo zypper refresh
sudo zypper update -y

Adding SLES SELinux repository

The OpenSUSE SELinux repository must be enabled. This repository is not added by default, and you need to enable it for the version of SLES you are running. Run the following commands to add it:

sles_version="$(. /etc/os-release && echo "${VERSION_ID##*.}")" opensuse_repo="https://download.opensuse.org/repositories/security:SELinux/SLE_15_SP$sles_version/security:SELinux.repo"
sudo zypper addrepo $opensuse_repo 

Uninstall old versions

If older versions of docker are installed in the system, uninstall them, along with associated dependencies.

sudo zypper remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine \
                  runc

Installing docker

There are multiple ways of installing docker in SLES. You can:

  • Set up docker repositories. This is recommended as you can even upgrade docker once set up
  • Download rpm and install manually
  • You can choose an automated convenience scripts to install Docker

Install using the repository

The docker packages are not found in the default SLESrepositories. You need to set up the Docker repository when installing docker in a new system.

Install the yum-utils package (which provides the yum-config-manager utility) and set up the stable repository.

sudo zypper addrepo https://download.docker.com/linux/sles/docker-ce.repo

To install the latest version of Docker Engine and containerd:

sudo zypper install docker-ce docker-ce-cli containerd.io

This command installs Docker, but it doesn’t start Docker. It also creates a docker group, however, it doesn’t add any users to the group by default.

To install a specific version of Docker Engine, list the available versions in the repo, then select and install:

a. List and sort the versions available in your repo. This example sorts results by version number, highest to lowest, and is truncated:

$ sudo zypper search -s --match-exact docker-ce | sort -r
Installed Packages
docker-ce.x86_64               3:20.10.9-3.el8                 docker-ce-stable
docker-ce.x86_64               3:20.10.9-3.el8                 @docker-ce-stable
docker-ce.x86_64               3:20.10.8-3.el8                 docker-ce-stable
docker-ce.x86_64               3:20.10.7-3.el8                 docker-ce-stable
Available Packages

The above command will list packages based on which repositories are enabled.

Install a specific version by its fully qualified package name, which is the package name (docker-ce) plus the version string (2nd column) starting at the first colon (:), up to the first hyphen, separated by a hyphen (-). For example3:20.10.7.

sudo zypper install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

Install using a package

If for any reason you can not use docker’s repository for the installation, you can download an rpm package and install manually.

Go to https://download.docker.com/linux/sles/ and choose your version of SLES. Then browse to15/s390x/stable/Packages/ and download the .rpm file for the Docker version you want to install

Install Docker Engine, changing the path below to the path where you downloaded the Docker package.

sudo zypper install /path/to/package.rpm

Docker is installed but not started. The docker group is created, but no users are added to the group.

Install using the convenience script

Docker provides a convenience script at get.docker.com to install Docker into development environments quickly and non-interactively. The convenience script is not recommended for production environments, but can be used as an example to create a provisioning script that is tailored to your needs. 

The script requires root or sudo privileges to run. The script attempts to detect your Linux distribution and version and configure your package management system for you, and does not allow you to customize most installation parameters. The script installs dependencies and recommendations without asking for confirmation. By default, the script installs the latest stable release of Docker, containerd, and runc.

You can run the script with the DRY_RUN=1 option to learn what steps the script will execute during installation:

curl -fsSL https://get.docker.com -o get-docker.sh
DRY_RUN=1 sh ./get-docker.sh

This downloads the script from get.docker.com and runs it to install the latest stable release of Docker on Linux:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Starting and enabling docker

On RPM based distributions, such as CentOS, Fedora, RHEL or SLES, you need to start it manually using the appropriate systemctl or service command. Non-root users cannot run Docker commands by default.

Use this command to start docker

sudo systemctl start docker

Confirm that docker is running by issuing the status command

$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2021-10-15 03:58:33 UTC; 20s ago
     Docs: https://docs.docker.com
 Main PID: 1462739 (dockerd)
    Tasks: 8
   Memory: 127.2M
   CGroup: /system.slice/docker.service
           └─1462739 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Oct 15 03:58:33 test-db-server dockerd[1462739]: time="2021-10-15T03:58:33.127140137Z" level=error m>
Oct 15 03:58:33 test-db-server dockerd[1462739]: time="2021-10-15T03:58:33.152784201Z" level=warning>

To enable docker on boot, use this command:

sudo systemctl enable docker

Docker will not work for no-root users or without sudo, you will get the error below if you attempt.

$ docker ps
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied

To use docker without Sudo, add the current user to the docker group then re-login.

Add the user to the docker group:

$ sudo usermod -aG docker ${USER}

Then relogin as the user

$ sudo su - ${USER}

Then check that you are now part of docker

$ id
uid=1000(citizix) gid=1000(citizix) groups=1000(citizix),4(adm),190(systemd-journal),985(docker)

Now we can confirm that everything is working by issuing the docker run command for the hello-world image:

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51
Status: Downloaded newer image for hello-world:latest

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

Uninstalling Docker

If you no longer need docker in the system, use these commands to uninstall it

sudo zypper remove docker-ce docker-ce-cli containerd.io
  1. Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

You must delete any edited configuration files manually.

Conclusion

We have managed to install docker on a SLES system either using the repository or downloading an rpm then installing it or using a convenience script.

Last updated on Oct 14, 2024 11:46 +0300
comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy