I want to store the images and containers to the different folders. such as all images are saved to ‘/mnt/docker-images’, and all containers are saved to ‘/mnt/docker-containers’.
It is not possible like that, but you can configure the docker data-root folder to use a different folder than /var/lib/docker like this:
Add the data-root entry to /etc/docker/daemon.json (needs to be created if it doesn’t already exist):
{
"data-root": "/mnt/docker-root"
}
Restart the docker engine to use the new data root: sudo systemctl start docker
Though, it will be the complete docker root data folder, which contains the whole configuration. It will not work, if this is a mount point for a network share. And generally you will want to make sure the mounted filesystem is supported as backing filesystem for the overlay2 storage driver.
Note: there is no supported docker-ce release for RHEL, except for the s390 architecture.
Just to extend @meyay’s answer and explain why it is not possible:
Docker stores the filesystem layers of containers and images in the same folder so there is no way to separate those. There is an “image” and a “containers” folder but those contain only metadata and not the filesystem so it wouldn’t even make sense to move those to another partition for about 20 megabytes and 200 kilobytes for example.