Docker is a free and open-source tool that allows you to build and run containers on your Linux system. It allows you to create lightweight and portable application images that run on any platform.
Docker Compose is a free and open-source tool that allows you to define, visualize, and run multiple applications in a containerized environment. It uses a YAML file to define different applications and services. After defining the services in the YAML file, you can start all of them using a single command.
In this post, we will show you how to install Docker and Docker Compose in Rocky Linux 8.
Step 1 – Install Docker CE
By default, the Docker package is not included in the RockyLinux default repository, so you will need to create a Docker CE repo.
You can create it using the following commands:
dnf update -y dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
Next, install Docker CE by running the following command:
dnf install docker-ce -y
Once Docker is installed, start the Docker service and enable it to start at system reboot.
systemctl start docker systemctl enable docker
You can verify the status of the Docker service using the following command:
systemctl status docker
Sample output:
● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2021-10-12 14:32:46 UTC; 3s ago Docs: https://docs.docker.com Main PID: 10474 (dockerd) Tasks: 8 Memory: 32.0M CGroup: /system.slice/docker.service └─10474 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock Oct 12 14:32:45 RockyLinux8 dockerd[10474]: time="2021-10-12T14:32:45.723802786Z" level=error msg="Failed to built-in GetDriver graph btrfs /v> Oct 12 14:32:46 RockyLinux8 dockerd[10474]: time="2021-10-12T14:32:46.156090877Z" level=warning msg="Your kernel does not support cgroup blkio> Oct 12 14:32:46 RockyLinux8 dockerd[10474]: time="2021-10-12T14:32:46.156145109Z" level=warning msg="Your kernel does not support cgroup blkio> Oct 12 14:32:46 RockyLinux8 dockerd[10474]: time="2021-10-12T14:32:46.156457478Z" level=info msg="Loading containers: start." Oct 12 14:32:46 RockyLinux8 dockerd[10474]: time="2021-10-12T14:32:46.573226503Z" level=info msg="Default bridge (docker0) is assigned with an> Oct 12 14:32:46 RockyLinux8 dockerd[10474]: time="2021-10-12T14:32:46.742379418Z" level=info msg="Loading containers: done." Oct 12 14:32:46 RockyLinux8 dockerd[10474]: time="2021-10-12T14:32:46.771012571Z" level=info msg="Docker daemon" commit=79ea9d3 graphdriver(s)> Oct 12 14:32:46 RockyLinux8 dockerd[10474]: time="2021-10-12T14:32:46.771196748Z" level=info msg="Daemon has completed initialization" Oct 12 14:32:46 RockyLinux8 systemd[1]: Started Docker Application Container Engine. Oct 12 14:32:46 RockyLinux8 dockerd[10474]: time="2021-10-12T14:32:46.808331498Z" level=info msg="API listen on /var/run/docker.sock"
To verify the Docker version with additional information, run the following command:
docker info
You will get the following output:
Client: Context: default Debug Mode: false Plugins: app: Docker App (Docker Inc., v0.9.1-beta3) buildx: Build with BuildKit (Docker Inc., v0.6.3-docker) scan: Docker Scan (Docker Inc., v0.8.0) Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 20.10.9 Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: true userxattr: false Logging Driver: json-file Cgroup Driver: cgroupfs Cgroup Version: 1 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc Default Runtime: runc Init Binary: docker-init containerd version: 5b46e404f6b9f661a205e28d59c982d3634148f8 runc version: v1.0.2-0-g52b36a2 init version: de40ad0 Security Options: seccomp Profile: default Kernel Version: 4.18.0-305.7.1.el8_4.x86_64 Operating System: Rocky Linux 8.4 (Green Obsidian) OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 3.649GiB Name: RockyLinux8 ID: QF4C:I2ML:INX7:RKY7:2X5A:YEQB:UJJW:LS35:LPMZ:LIKS:2WB2:P33U Docker Root Dir: /var/lib/docker Debug Mode: false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false
Step 2 – Verify Docker Installation
After installing Docker, you will need to test whether it’s working.
You can use Docker’s hello-world container to test Docker.
docker run hello-world
This will download the hello-world docker image to your system:
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:9ade9cc2e26189a19c2e8854b9c8f1e14829b51c55a630ee675a5a9540ef6ccf Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
You can verify the downloaded image using the following command:
docker images
You will get the following output:
REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
Step 3 – Install Docker Compose
By default, the latest version of Docker Compose is not available in the Rocky Linux default repository, so you will need to download its binary to your system.
First, install the curl command utility with the following command:
dnf install -y curl
Next, download the latest version of Docker Compose with the following command:
curl -L https://github.com/docker/compose/releases/download/v2.0.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
Next, set executable permissions on the Docker Compose binary:
chmod +x /usr/local/bin/docker-compose
Next, verify the Docker Compose version using the following command:
docker-compose --version
You will get the following output:
Docker Compose version v2.0.1
Step 4 – Remove Docker and Docker Compose
If you want to remove the Docker package from your system, first stop the Docker service using the following command:
systemctl stop docker
Next, remove the Docker package using the following command:
dnf remove docker-ce -y
To remove Docker Compose, delete the Docker Compose binary using the following command:
rm -rf /usr/local/bin/docker-compose
Conclusion
In the above guide, we explained how to install Docker and Docker Compose on RockyLinux 8. You can now start creating a YAML for your application and deploy it in the containerized environment. Give it a try on your dedicated server from Atlantic.Net!