How Do You Install the docker.service File on RHEL 8.x?

One of the following problems occurs:

Problem scenario #1
You run some systemctl commands to start the Docker service, but you get this error: "Failed to enable unit: Unit file docker.service does not exist."
Or you run some other command and see this:
"Unit docker.service not found."
What should you do to get the docker.service file on a RHEL 8.x server?

Problem scenario #2
You are running a kubeadm command on RHEL 8, but you get this error:

[preflight] Running pre-flight checks
[WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service'
[WARNING IsDockerSystemdCheck]: detected "" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[WARNING FileExisting-ebtables]: ebtables not found in system path
[WARNING FileExisting-socat]: socat not found in system path
[WARNING FileExisting-tc]: tc not found in system path

You cannot find a docker.service file either. What should you do?
How do you troubleshoot "docker service is not enabled" when you run a kubeadm command?

Possible Solution #1
Run these commands (but replace "rhel" with "centos" if you are using CentOS):

sudo dnf config-manager --add-repo=https://download.docker.com/linux/rhel/docker-ce.repo
sudo dnf install docker-ce
sudo systemctl enable docker.service

Possible Solution #2
Run these commands (but replace "rhel" with "centos" if you are using CentOS):

sudo dnf config-manager --add-repo=https://download.docker.com/linux/rhel/docker-ce.repo
sed -i -e 's/baseurl=https:\/\/download\.docker\.com\/linux\/\(fedora\|rhel\)\/$releasever/baseurl\=https:\/\/download.docker.com\/linux\/centos\/$releasever/g' /etc/yum.repos.d/docker-ce.repo
sudo dnf install docker-ce
sudo systemctl enable docker.service

The second line above (with "sed") was taken from this posting.

Possible Solution #3
Here is another example (that was influenced by a StackOverflow.com posting) that was in /usr/lib/systemd/system/docker.service on a CentOS Stream release 8 server:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

After the file above is created, you should try running this command:

sudo systemctl enable docker.service

Possible Solution #4
Here is another example of a docker.service file. The file often "lives" in /usr/lib/systemd/system/. You should then try running this command:

sudo systemctl enable docker.service

Leave a comment

Your email address will not be published. Required fields are marked *