Installation
Method 1 - Convenience Script
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
<...>
If you would like to use Docker as a non-root user,
Approach 1
$ sudo sh -eux <<EOF
# Install newuidmap & newgidmap binaries
apt-get install -y uidmap
EOF
$ dockerd-rootless-setuptool.sh install
# To run docker.service on system startup, run:
$ sudo loginctl enable-linger sw
# Make sure the following environment variables are set (or add them to ~/.bashrc):
export PATH=/usr/bin:$PATH
export DOCKER_HOST=unix:///run/user/1000/docker.sock
# Verify that you can run docker commands without sudo.
$ docker run hello-world
Approach 2
you should now consider adding your user to the “docker” group with something like:
$ sudo usermod -aG docker ${USER}
# 将当前用户切换到docker组中,且立即生效
$ newgrp docker
# Verify that you can run docker commands without sudo.
$ docker run hello-world
Method 2 - Using Repository
Uninstall Docker Engine
-
Uninstall the Docker Engine, CLI, and Containerd packages:
$ sudo apt-get purge docker-ce docker-ce-cli containerd.io
-
Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:
$ sudo rm -rf /var/lib/docker $ sudo rm -rf /var/lib/containerd
You must delete any edited configuration files manually.
管理
Start the Docker daemon
Start manually
Once Docker is installed, you need to start the Docker daemon. Most Linux distributions use systemctl
to start services.
$ sudo systemctl start docker
Reference
- https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository
- https://docs.docker.com/engine/install/linux-postinstall/
- https://www.digitalocean.com/community/questions/how-to-fix-docker-got-permission-denied-while-trying-to-connect-to-the-docker-daemon-socket