【Linux】Ubuntu 安装 Docker

Posted by 西维蜀黍 on 2020-05-01, Last Modified on 2022-10-10

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

  1. Uninstall the Docker Engine, CLI, and Containerd packages:

    $ sudo apt-get purge docker-ce docker-ce-cli containerd.io
    
  2. 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