系统首页

Ubuntu中Docker的安装与配置

来源:自通100    发布时间:2023-04-21 17:59:36    浏览:21

Docker 是一个用于开发、传送和运行应用程序的开放平台。Docker 使您能够将应用程序与基础设施分开,以便您可以快速交付软件。使用 Docker,您可以像管理应用程序一样管理基础设施。通过利用 Docker 的快速交付、测试和部署代码的方法,您可以显著减少编写代码和在生产中运行代码之间的延迟。 Docker(opens new window) 是个划时代的开源项目,它彻底释放了计算虚拟化的威力,极大提高了应用的维护效率,降低了云计算应用开发的成本!使用 Docker,可以让应用的部署、测试和分发都变得前所未有的高效和轻松! 无论是应用开发者、运维人员、还是其他信息技术从业人员,都有必要认识和掌握 Docker,节约有限的生命。

一、更新apt包索引:

sudo apt-get update

二、安装必备的软件包以允许apt通过 HTTPS 使用存储库(repository):

sudo apt-get install ca-certificates curl gnupg lsb-release

三、添加阿里云的GPG密钥:

sudo mkdir -p /etc/apt/keyrings

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

四、使用以下命令设置存储库

sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

五、安装最新版本的Docker(飞速安装)

sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

六、验证Docker是否安装成功

-- 查看docker 版本

docker version

七、启动Docker

1、安装完成后,运行如下命令验证 Docker 服务是否在运行

systemctl status docker

如果出现以下类似内容说明docker已正常启动:

root@licaipei-Virtual-Machine:/etc/apt/keyrings# systemctl status docker

● docker.service - Docker Application Container Engine

Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)

Active: active (running) since Fri 2023-04-21 17:38:02 CST; 51s ago

TriggeredBy: ● docker.socket

Docs: https://docs.docker.com

Main PID: 37684 (dockerd)

Tasks: 7

Memory: 23.4M

CPU: 263ms

CGroup: /system.slice/docker.service

└─37684 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

4月 21 17:38:01 licaipei-Virtual-Machine dockerd[37684]: time="2023-04-21T17:38:01.880387484+08:00" le>

4月 21 17:38:02 licaipei-Virtual-Machine dockerd[37684]: time="2023-04-21T17:38:02.069574397+08:00" le>

4月 21 17:38:02 licaipei-Virtual-Machine dockerd[37684]: time="2023-04-21T17:38:02.071602373+08:00" le>

4月 21 17:38:02 licaipei-Virtual-Machine dockerd[37684]: time="2023-04-21T17:38:02.459965777+08:00" le>

4月 21 17:38:02 licaipei-Virtual-Machine dockerd[37684]: time="2023-04-21T17:38:02.599183094+08:00" le>

4月 21 17:38:02 licaipei-Virtual-Machine dockerd[37684]: time="2023-04-21T17:38:02.827688032+08:00" le>

4月 21 17:38:02 licaipei-Virtual-Machine dockerd[37684]: time="2023-04-21T17:38:02.827994828+08:00" le>

4月 21 17:38:02 licaipei-Virtual-Machine dockerd[37684]: time="2023-04-21T17:38:02.957579062+08:00" le>

4月 21 17:38:02 licaipei-Virtual-Machine systemd[1]: Started Docker Application Container Engine.

4月 21 17:38:02 licaipei-Virtual-Machine dockerd[37684]: time="2023-04-21T17:38:02.964641976+08:00" le>

如果为启动执行启动命令进行启动

2、运行以下命令启动Docker服务

sudo systemctl start docker

3、设置Docker服务在每次开机时自动启动

sudo systemctl enable docker

4、查看docker运行状态

systemctl status docker

5、验证Docker是否运行正常

执行下面的命令会下载一个Docker测试镜像,并在容器中执行一个“hello-world”样例程序。

sudo docker run hello-world

如果你看到类似下方的输出,那么祝贺你,Docker能够正常运行在你的Ubuntu系统中了。

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中安装php7.4+mysql5.7+nginx

下一篇:Ubuntu中设置 SSH 通过密钥登录

标签云