【Docker】Docker 和 Docker Compose 安装

本文最后更新于:2022年11月4日 下午

本文介绍了 DockerDocker-compose 的安装。

本文参考来源:学习资料【非官方】:Docker - 从入门到实践

Docker 介绍

Docker 使用 Google 公司推出的 Go 语言 进行开发实现,基于 Linux 内核的 cgroup,namespace,以及 OverlayFS 类的 Union FS 等技术,对进程进行封装隔离,属于 操作系统层面的虚拟化技术。由于隔离的进程独立于宿主和其它的隔离的进程,因此也称其为容器

官网

官网:Docker
文档:Docker Documentation

Docker 安装

官方文档最新版本安装方式

Docker 分为 stable test 和 nightly 三个更新频道。
官方网站上有各种环境下的 安装指南,这里主要介绍 Docker 在 Linux 、Windows 10 和 macOS 上的安装。最新版本可以参考官方文档:
https://docs.docker.com/desktop/linux/install/

【推荐】使用脚本自动安装

在测试或开发环境中 Docker 官方为了简化安装流程,提供了一套便捷的安装脚本,Ubuntu 系统上可以使用这套脚本安装,另外可以通过 --mirror 选项使用国内源进行安装:
若你想安装测试版的 Docker, 请从 test.docker.com 获取脚本。

1
2
3
4
# curl -fsSL test.docker.com -o get-docker.sh
curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh --mirror Aliyun
# sudo sh get-docker.sh --mirror AzureChinaCloud

Ubuntu包管理器

两种安装方式:

1
apt install docker.io

或者有snap的话:

1
snap install docker

用snap安装会一起把 Docker-compose 也安装了,但安装的版本比较低。是 docker-compose version 1.25.0

测试 Docker 是否安装正确

查看Docker版本:docker -v

测试启动容器:

1
$ docker run --rm hello-world
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
4ee5c797bcd7: Pull complete
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
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.
(arm32v7)
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

1
2
$ sudo systemctl enable docker
$ sudo systemctl start docker

Docker-compose 手动安装

Linux 上我们可以从 Github 上下载它的二进制包来使用,最新发行的版本地址:

https://github.com/docker/compose/releases

运行以下命令以下载 Docker Compose 的当前稳定版本:

1
sudo curl -L "https://github.com/docker/compose/releases/download/v2.6.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

要安装其他版本的 Compose,请替换 v2.2.2。

国内镜像加速:

1
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.6.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

将可执行权限应用于二进制文件:

1
sudo chmod +x /usr/local/bin/docker-compose

创建软链:

1
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

测试是否安装成功:

1
docker-compose --version

Docker-compose 基础使用

在测试目录中,执行以下命令来启动应用程序:

1
docker-compose up

如果你想在后台执行该服务可以加上 -d 参数:

1
docker-compose up -d

【Docker】Docker 和 Docker Compose 安装
https://pawswrite.xyz/posts/30011.html
作者
Rainbow
发布于
2022年6月1日
许可协议