Skip to content

Some Operations After Installing Docker and Podman

After installing Docker, there are usually a few follow-up tasks to complete. This note provides an all-in-one reference.

1. Run Docker commands without sudo

Add the current user to the docker group:

cat /etc/group | grep docker # Check whether the docker group exists
groups # List your user groups and confirm whether you are in the docker group

# If the docker group does not exist, create it:
sudo groupadd docker

# Add the current user to the docker group
sudo gpasswd -a ${USER} docker

# Restart the service
sudo service docker restart

# Switch groups to refresh the cached group list
newgrp - docker;
# Run the commands line by line. In some cases, the second command does not take effect when both are run in a batch.
newgrp - `groups ${USER} | cut -d' ' -f1`;
# Alternatively, log out and log back in
pkill X

2. Configure registry mirrors

(1). Configure Docker registry mirrors

Create or edit /etc/docker/daemon.json:

    {
        "registry-mirrors": [
            "https://1nj0zren.mirror.aliyuncs.com",
            "https://docker.mirrors.ustc.edu.cn",
            "http://f1361db2.m.daocloud.io",
            "https://registry.docker-cn.com"
        ]
    }
  • You can replace these mirrors with other available registry mirror addresses.

(2). Configure Podman registry acceleration

Edit /etc/containers/registries.conf and use the following pattern:

[[registry]]
prefix = "docker.io"
location = "xxxxxxxx.mirror.aliyuncs.com"

3. Change Docker's default storage location

(1). Stop the Docker service

sudo systemctl stop docker

(2). Move the data directory to the target location

mv /var/lib/docker/ /home/dockerdata

ln -s /home/dockerdata/ /var/lib/docker

(4). Restart Docker

sudo systemctl restart docker

4. Docker.io mirrors in China

Docker official China mirror: https://registry.docker-cn.com

NetEase: http://hub-mirror.c.163.com

USTC: http://docker.mirrors.ustc.edu.cn

Alibaba Cloud: http://<your ID>.mirror.aliyuncs.com

REF

[1].http://www.markjour.com/article/docker-no-root.html

[2].https://juejin.cn/post/6844903840303546376

[3].https://blog.csdn.net/glongljl/article/details/80158297

[4].https://blog.csdn.net/qq_21933797/article/details/115186907