咸鱼

咸鱼是以盐腌渍后,晒干的鱼

0%

3、Docker-Compose

Docker Compose 是 Docker 官方编排(Orchestration)项目之一,负责快速的部署分布式应用。

下载 Docker Compose:

【文档】

1
2
3
4
# 20230614最新版本
$ sudo curl -SL https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose

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

修改为可执行文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ sudo chmod +x /usr/local/bin/docker-compose
# 如果提示找不到命令,则看下面方法环境变量
$ vim ~/.bashrc
# 最后一行加入
alias sudo="sudo env PATH=$PATH"

$ source ~/.bashrc

# 查看版本即成功
$ docker-compose version
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019

compose编排一个服务

1
2
3
4
5
6
7
8
9
10
11
$ mkdir test-tomcat
$ cd test-tomcat
$ vim docker-compose.yml
version: '3.7'
services:
mytomcat:
restart: always
image: tomcat
container_name: mytomcat
ports:
- "8080:8080"

compose编排多个服务

compose编排多个服务.png

compose启动

1
$ docker-compose up

compose守护启动

1
2
$ docker-compose up -d
$ docker-compose logs mytomcat

compose关闭

1
2
$ docker-compose down
$ docker ps -a

compose关闭并删除volumes数据

1
$ docker-compose down --volumes