How to Install and Setup Docker on Centos 8 Quickstart.
Deploying applications can sometimes create unexpected problems for developers. While your code may work just fine in one environment, the same code may not work as expected, or may not work at all in a different computing environment.
The 5 Top Linux Distros You Should Be Using
This difference in computing environments is always a bottleneck for software development and testing. You can of course use a virtual machine as a test environment.
However, virtual machines often take up a lot of space and use up CPU and memory resources on the host system. Fortunately, with Docker, developers can easily develop and deploy their applications in containers. In this guide, we’ll show you how to install Docker on CentOS 8.
So, What is Docker?
Docker is an open-source containerization framework that allows developers to package their code or applications inside containers. Containers are self-contained instances that come with their own libraries and dependencies.
This will take care of any missing libraries or dependency issues during installation when the application is running on different platforms. Compared to running VMs, Docker is lightweight, takes up less hard disk space, is economical in resources, and has better performance and efficiency.
Installing Docker on CentOS 8
To install Docker on your system, make sure you have the following before proceeding:
When everything is clear, follow the instructions to install Docker on CentOS.
Step 1. Update your system
First, log into the server and update the system as follows:
$ sudo dnf update
When prompted to proceed with the installation, simply press “Y” and press the ENTER key on your keyboard. The system will update all packages with newer versions, including kernel, systemd, and other application packages.
This may take several minutes depending on when your system was last updated. So, wait for the system to update the packages.
Step 2.
Add the Docker repository
After completing the upgrade, you need to add the Docker repository to the system. This way you will be able to install Docker using the DFN package manager.
To add a repository, run the following command in a terminal:
[user @ centos8 ~] $ sudo dnf config-manager –add-repo = https: //download.docker.com/linux/centos/docker-ce.repo
You should get simple output confirming the repo has been added.
Once the Docker repository has been created, it is worth taking a look at the available Docker versions. You can do this by entering the command:
[user @ centos8 ~] $ sudo dnf list docker-ce
The output shows the Docker package name, architecture, and version, as well as some of them, as you can see in the output.
Configure NGINX Reverse Proxy – Step by Step
Step 3:
Install Docker-CE
Next, we’re going to install Docker-CE, which is short for Docker Community Edition. Disclaimer: The latest version of Docker is usually not available for all repositories. Therefore, we will add the –nobest flag to the command as follows:
[user @ centos8 ~] $ sudo dnf install docker-ce –nobest
The –nobest flag allows us to set the most preferred option for our server instance. As before, press “Y” and press “Next” to continue.
Once the installation is complete, confirm the Docker version on the command line as shown.
$ docker –version
To run docker commands as sudo user add the user to docker groups as shown.
$ sudo usermod -aG docker $ USER
Restart your system for this to take effect.
Step 4: Manage the Docker Service
Docker works like a daemon, as do services like SSH. This means that you can perform tasks such as checking its status, starting and stopping, and so on, to mention a few.
Docker is currently inactive and down. To start the Docker service, run:
$ sudo systemctl start docker
Check if Docker is running by calling:
State docker $ sudo systemctl
The output confirms that Docker is up and running.
Also, you can allow docker to run every time you boot or reboot as follows.
$ sudo systemctl enable docker
Similarly, you can disable Docker like this:
$ sudo systemctl disable docker
Step 5. Using Docker to Perform Docker Tasks
As we explained earlier in the introduction, Docker is a containerization framework that manages container images, which are isolated units with their own libraries, dependencies, and configuration files. You can build your own container image, or get one from the Docker Hub, which is a huge repository filled with thousands of images from major vendors.
First, we’ll run a simulation to test if Docker is working as expected. To do this, we will retrieve the ‘Hello world’ image from the Docker hub as shown.
$ docker run hello-world
You should get the result below as the container prints the message “Hello from Docker!”
As you can see from the output, Docker simply pulled the hello-world image from the Docker hub, created the container image, and launched the container, which then sent a “Hello from Docker!” Message to the terminal.
To pull only the docker image without starting the container, use the syntax:
$ docker pull image-name
For example, let’s try to get an image of the Apache web server.
$ docker pull httpd
To confirm that the docker images are on the system, issue the command:
$ docker images
In the output, we have 2 images: a hello-world image and an httpd Apache web server image. The output gives you the repository name, image tag, image id, creation time, and image size.
With the image on the system, you can rotate the container by running:
The Most Common Video Formats and Codecs Explained
$ docker run image-name
This launches the container in the foreground. However, this is not always desirable as you will not be able to run other commands. A workaround is to run the image in the background so you can continue running other commands.
To run the container image in the background, use the -d option.
$ docker run -d image-name
For example, to run an Apache container image, run:
$ docker run -d httpd
To check running containers, use the command:
$ docker ps
Again, you will get verbose output about the container, including the container ID, the image the container was created from, creation time and status, and the container name.
When you are done starting the container, you can stop it using the syntax:
$ docker stop CONTAINER-ID
For example, to stop the httpd container, run:
$ docker stop c07ffb3fc13f
You can verify that the container is stopped using the docker ps command as explained earlier.
$ docker ps
In addition, you can add the -a flag to view all containers – running or stopped.
$ docker ps -a
To delete an image, you must first stop the container as shown earlier. After stopping, use the below syntax to remove the image.
$ docker rmi -f REPOSITORY NAME or IMAGE ID
For example, to remove the hello-world image, pause the image as follows.
$ docker stop 043df63a1b29
Then delete the image as follows.
$ docker rmi -f hello world
There are many docker teams out there, but we decided to give you a general idea of ​​what you can achieve with docker and docker images.
Conclusion
While Docker has been deprecated in favor of podman and buildah, which are containerization tools, it is still widely used by developers and newbies looking to get started with containerization. Hopefully, you can now easily install Docker and run Docker commands.
How to Install and Setup Docker on Centos 8 Quickstart
- Ready CentOS 8. Instance
- SSH access to the server with a configured sudo user.
- Stable and reliable internet connection.
- How to Install and Setup Docker on Centos 8 Quickstart