Install and Run Docker on NON ROOT

本文介绍如何在Ubuntu系统中设置Docker以便非root用户能够运行Docker命令,包括创建docker组、添加用户到该组及验证设置的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://docs.docker.com/installation/ubuntulinux/#giving-non-root-access

https://ubuntuincident.wordpress.com/2014/01/10/docker/


Create a docker group

The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can access it with sudo. For this reason, docker daemon always runs as the root user.

To avoid having to use sudo when you use the docker command, create a Unix group called dockerand add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.

Warning: The docker group is equivalent to the root user; For details on how this impacts security in your system, see Docker Daemon Attack Surface for details.

To create the docker group and add your user:

  1. Log into Ubuntu as a user with sudo privileges.

    This procedure assumes you log in as the ubuntu user.

  2. Create the docker group and add your user.

    $ sudo usermod -aG docker ubuntu
  3. Log out and log back in.

    This ensures your user is running with the correct permissions.

  4. Verify your work by running docker without sudo.

    $ docker run hello-world



Execute docker as non-root
As you noticed, docker must be executed with sudo. If you want to execute it with your non-root account, here is what to do:

1
2
3
4
5
6
# create the 'docker' group
$ sudo groupadd docker  # probably it already exists
# add your user to the 'docker' group
$ sudo gpasswd -a USER docker  # replace USER with your user name
# restart the service
$ sudo service docker restart

You will have to log out and log back in to make the group settings active on your account. After that you can launch docker without sudo:

1
2
3
4
5
6
7
$ docker images
REPOSITORY          TAG                 ID                  CREATED             SIZE
ubuntu              12.04               8dbd9e392a96        4 months ago        131.5 MB (virtual 131.5 MB)
ubuntu              12.10               b750fe79269d        5 months ago        24.65 kB (virtual 180.1 MB)
ubuntu              latest              8dbd9e392a96        4 months ago        131.5 MB (virtual 131.5 MB)
ubuntu              precise             8dbd9e392a96        4 months ago        131.5 MB (virtual 131.5 MB)
ubuntu              quantal             b750fe79269d        5 months ago        24.65 kB (virtual 180.1 MB)







转载于:https://my.oschina.net/dexterman/blog/397450

# Executing docker install script, commit: + sh -c apt-get -qq update >/dev/null + sh -c DEBIAN_FRONTEND=noninteractive apt-get -y -qq install ca-certificates curl >/dev/null + sh -c install -m 0755 -d /etc/apt/keyrings + sh -c curl -fsSL "https://mirrors.aliyun.com/docker-ce/linux/debian/gpg" -o /etc/apt/keyrings/docker.asc + sh -c chmod a+r /etc/apt/keyrings/docker.asc + sh -c echo "deb [arch=armhf signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.aliyun.com/docker-ce/linux/debian bookworm stable" > /etc/apt/sources.list.d/docker.list + sh -c apt-get -qq update >/dev/null + sh -c DEBIAN_FRONTEND=noninteractive apt-get -y -qq install docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin >/dev/null + sh -c docker version Client: Docker Engine - Community Version: 28.0.4 API version: 1.48 Go version: go1.23.7 Git commit: b8034c0 Built: Tue Mar 25 15:08:06 2025 OS/Arch: linux/arm Context: default Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? ================================================================================ To run Docker as a non-privileged user, consider setting up the Docker daemon in rootless mode for your user: dockerd-rootless-setuptool.sh install Visit https://docs.docker.com/go/rootless/ to learn about rootless mode. To run the Docker daemon as a fully privileged service, but granting non-root users access, refer to https://docs.docker.com/go/daemon-access/ WARNING: Access to the remote API on a privileged Docker daemon is equivalent to root access on the host. Refer to the 'Docker daemon attack surface' documentation for details: https://docs.docker.com/go/attack-surface/这个问题怎么解决
最新发布
03-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值