(一)Docker安装
Docker 是一个开源的容器化平台,它允许你构建,测试,并且作为可移动的容器去部署应用,这些容器可以在任何地方运行。一个容器表示一个应用的运行环境,并且包含软件运行所需要的所有依赖软件。
一、安装docker
(1)首先,更新软件包索引,并且安装必要的依赖软件,来添加一个新的 HTTPS 软件源:
命令:
sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
(2)使用下面的 curl 导入源仓库的 GPG key:
命令:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add
(3)将 Docker APT 软件源添加到你的系统:
命令:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
(4)安装 Docker 最新版本,运行下面的命令。
命令:
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
二、验证安装过程
想要验证 Docker 是否已经成功被安装,你可以执行docker命令,前面不需要加`sudo, 我们将会运行一个测试容器。
docker container run hello-world
输出:
root@linux-pc:~# docker container run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete
Digest: sha256:dcba6daec718f547568c562956fa47e1b03673dd010fe6ee58ca806767031d1c
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
三、卸载docker
在卸载 Docker 之前,你最好移除所有的容器,镜像,卷和网络。
运行下面的命令停止所有正在运行的容器,并且移除所有的 docker 对象:
命令:
docker container stop $(docker container ls -aq)
docker system prune -a --volumes
现在你可以使用apt像卸载其他软件包一样来卸载 Docker:
命令:
sudo apt purge docker-ce
sudo apt autoremove