Change docker data location on RHEL8

This article will show you how to change default docker data location

Stop docker service if it’s running

Run below command to stop docker service

sudo systemctl stop docker.service
sudo systemctl stop docker.socket

Verify docker is stopped

sudo systemctl status docker
# Example output
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Fri 2023-04-07 20:29:54 ADT; 21s ago
     Docs: https://docs.docker.com
  Process: 21921 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=0/SUCCESS)
 Main PID: 21921 (code=exited, status=0/SUCCESS)

Update docker service file

Edit /lib/systemd/system/docker.service file

sudo vi /lib/systemd/system/docker.service

Make change to line contains: ExecStart=/usr/bin/dockerd -H fd:// –containerd=/run/containerd/containerd.sock

ExecStart=/usr/bin/dockerd --data-root /your/path/docker -H fd:// --containerd=/run/containerd/containerd.sock

Save and exit

Copy existing docker data to new folder

Run below command

sudo rsync -aqxP /var/lib/docker/ /your/path/docker

Reload system deamon config and start docker

Run below commands

sudo systemctl daemon-reload
sudo systemctl start docker

Verify docker is running correctly

sudo systemctl status docker

Scroll to Top