Oracle Linux is an open-source RHEL-based system and a good alternative to CentOS and RHEL. Oracle Linux 9 is the latest version Oracle Linux series and the best alternative to CentOS 8 Linux that came to its end of life. Oracle supports a variety of services/applications that any Linux system can like Webhosting and many more. In this article, we will be focusing on how to install and run Docker CE on Oracle Linux 9.
Docker is an open-source operating system virtualization technology that allows one to run containerized software applications on Linux, Windows, and macOS. Docker exists in two different categories; Docker CE(Community Edition) is an open-source version of Docker that allows to run and deploy Docker containers freely at zero cost. On the other hand, Docker EE(Enterprise Edition) is an integrated, fully supported, and certified container platform that runs on RHEL, Oracle Linux, SUSE Linux Enterprise Server (SLES), AWS, Azure, Ubuntu, and Windows 2016.
Alternatively, you can as well run containers on Oracle Linux 9 using Podman instead of Docker CE which is daemonless, rootless container engine founded by RedHat.
Run the below command to rebuild the repo cache and update installed packages.
sudo yum update
Add Docker Repository to Oracle Linux 9
First, install the necessary utilities to enable you to add the docker repo to the system.
sudo yum install -y yum-utils
Use the yum-config-manger tool to add docker repo in Oracle Linux 9.
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
Confirm if the Docker repo has been added and exists in the repo list.
$ sudo dnf repolist
repo id repo name
docker-ce-stable Docker CE Stable - x86_64
ol9_UEKR7 Oracle Linux 9 UEK Release 7 (x86_64)
ol9_appstream Oracle Linux 9 Application Stream Packages (x86_64)
ol9_baseos_latest Oracle Linux 9 BaseOS Latest (x86_64)
Install Docker CE Engine on Oracle Linux 9
Remove existing Docker Engine before proceeding with installation on Oracle Linux 9.
$ sudo yum remove docker docker-* podman runc
Transaction Summary
===================================================================================================================================================================================================================
Remove 18 Packages
Freed space: 98 M
Is this ok [y/N]: y
Go ahead and execute the below command to install Docker Engine in Oracle Linux 9.
sudo yum install docker-ce docker-ce-cli containerd.io
The screen below shows a number of dependencies to be installed. Accept the installation to continue.
Transaction Summary
===================================================================================================================================================================================================================
Install 9 Packages
Total download size: 91 M
Installed size: 388 M
Is this ok [y/N]: Y
Accept the request to import the GPG key.
.....
Docker CE Stable - x86_64 5.4 kB/s | 1.6 kB 00:00
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm) <[email protected]>"
Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
From : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: Y
Starting Docker on Oracle Linux 9
Now that installation is complete and successful, start the Docker service using the below command.
sudo systemctl start docker
Enable Docker to make it start automatically when the system boots.
$ sudo systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
Check status to confirm that the Docker service is up and running as expected.
sudo systemctl status docker
Run Docker Commands as Non-Root User.
By default, running any Docker command needs root privileges. Therefore, as a normal user, you will need sudo command to access docker else you will get a permission denied error. To allow access to the Docker by a normal user (without sudo), you will need to add a user to the docker group.
sudo usermod -aG docker $USER
newgrp docker
Testing and Using Docker CE on Oracle Linux 9.
We are going to create our first Nginx web server docker container to test and verify our installation. To achieve this, run the below command in the terminal to pull the Nginx image.
$ docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
1efc276f4ff9: Pull complete
baf2da91597d: Pull complete
05396a986fd3: Pull complete
6a17c8e7063d: Pull complete
27e0d286aeab: Pull complete
b1349eea8fc5: Pull complete
Digest: sha256:790711e34858c9b0741edffef6ed3d8199d8faa33f2870dea5db70f16384df79
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
Now use docker run command to deploy the Nginx container in Oracle Linux 9.
$ docker run --name webserver -d nginx
27c78336b24db21bace8df21fa5d3941688d35e8ee0253f10ecf0e3c6f800c30
View and verify your deployed container.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
27c78336b24d nginx "/docker-entrypoint.…" About a minute ago Up About a minute 80/tcp webserver
Building and Use of Dockerfile.
Docker is a docker configuration file where you can write and declare variables in code format to deploy a container or even build a docker image. Am going to show you how you can create a simple docker file to build an Nginx image for yourself.
Create your docker file and add the following lines of code.
$ sudo vim vim dockerfile
FROM oraclelinux:9
LABEL maintainer="[email protected]"
RUN dnf update -y
RUN dnf upgrade -y
RUN dnf install epel-release -y
RUN dnf install nginx -y
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
- FROM: Represents the base of our image.
- LABEL: Adding metadata to image
- RUN: Execute the subsequent command on the line.
- EXPOSE: Allow the container to listen to a specific port.
- CMD: Default argument for ENTRYPOINT
Run the below command to build your image by executing your dockerfile.
docker build -t nginx-image:1.0.0 -f dockerfile /home/collins/images/
Use -f if you are not using the default dockerfile. Also, specify the location of your docker file of use .(dot) if you are working from the directory where your dockerfile is.
The built process has been completed successfully. You can view your newly created image using the docker images command.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx-image 1.0.0 3aa8e4275061 21 minutes ago 316MB
You can run a container using your images as shown below.
docker run --name webserver-2 -p 80:80 -d nginx-image:1.0.0
See running containers.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f1ebf601ae71 nginx-image:1.0.0 "nginx -g 'daemon of…" 5 seconds ago Up 4 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp webserver-2
27c78336b24d nginx "/docker-entrypoint.…" About an hour ago Up About an hour 80/tcp webserver
Since we have forwarded to port 80 on the external network, we can access Nginx by visiting the IP address of your server in a browser.
To restart containers use the docker restart command and specify the name of the container.
$ docker restart webserver
To remove the container, use the docker rm command and ensure that the container is stopped.
docker stop webserver
docker rm webserver
To remove the image as well use the docker rmi command and specify the name of the image you want to delete.
$ docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:790711e34858c9b0741edffef6ed3d8199d8faa33f2870dea5db70f16384df79
Deleted: sha256:b692a91e4e1582db97076184dae0b2f4a7a86b68c4fe6f91affa50ae06369bf5
Deleted: sha256:20fe57e949a4f70bf714590d9d5a78d158d12f4619d148619427a86dfc2e5a7a
Deleted: sha256:042a89e2d80d230c47e0f2add6e13a5958cf18b039f04a3751200937ef76ba03
Deleted: sha256:9e20f968300754f2d3ace5b726448b9a4249bb8196aded53b36ae8b6d3e8c174
Deleted: sha256:15e9cede496de643a978a58c0b49ef7beea83b368dfefc2e46fa0e8dd589f099
Deleted: sha256:d2850ddb0c4ca9f6289f624b27f987873e556c41250f5c5ed47a69c6c2529e4b
Deleted: sha256:92a4e8a3140f7a04a0e5a15793adef2d0e8889ed306a8f95a6cfb67cecb5f212
We fully covered how you can install and use Docker Engine on Oracle Linux 9 systematically in this guide. You can now deploy and run your containerized applications on Oracle Linux 9 and also use dockerfile to build your own Docker image. Thank you for your support and feel free to leave a comment.
Explore More with CloudSpinx
Looking to streamline your tech stack? Look no further, here at CloudSpinx, we deliver robust solutions tailored to your needs.
Learn more about how we can support your journey with CloudSpinx.