Docker基础(一)Docker安装

本文详细介绍了如何在Linux系统上安装Docker,包括添加软件源、安装步骤、验证安装、运行测试容器以及如何卸载Docker并清理资源。

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

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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Du_zhe_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值