docker 命令转 docker-compose
最后更新于:2022-04-02 03:06:05
[TOC]
> [参考](https://beginor.github.io/2017/06/08/use-compose-instead-of-run.html)
## demo
```
# PostGIS DB
docker run \
--datach \
--publish 5432:5432 \
--name postgis \
--restart unless-stopped \
--volume $(pwd)/db/data:/var/lib/postgresql/data \
beginor/postgis:9.3
# GeoServer Web
docker run \
--detach \
--publish 8080:8080 \
--name geoserver \
--restart unless-stopped \
--volume $(pwd)/geoserver/data_dir:/geoserver/data_dir \
--volume $(pwd)/geoserver/logs:/geoserver/logs \
--hostname geoserver \
--link postgis:postgis \
beginor/geoserver:2.11.0
```
等价于
docker-compose.yml
```
version: "3"
services:
web:
image: beginor/geoserver:2.11.1
container_name: geoserver-web
hostname: geoserver-web
ports:
- 8080:8080
volumes:
- ./web/data_dir:/geoserver/data_dir
- ./web/logs:/geoserver/logs
restart: unless-stopped
links:
- database:database
database:
image: beginor/postgis:9.3
container_name: postgis
hostname: postgis
ports:
- 5432:5432
volumes:
- ./database/data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: 1q2w3e4R
restart: unless-stopped
```
启动
`docker-compose up -d`
停止
`docker-compose down`
';