Docker-Compose 的简要使用

Docker-Compose 的简要使用。~~~sh docker-compose up

docker-compose 常用命令

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 启动相关容器
docker-compose up
# 后台启动
docker-compose up -d
# 指定文件
docker-compose -f docker-compose.yml up -d
# 指定项目名称
docker-compose -p mine-project -f docker-compose.yml up -d


# 停止并删除相关容器及其相关网络、卷等
docker-compose down

# 拉取相关镜像
docker-compose pull

docker-compose.yml 文件模板

Compose file version 3 reference | Docker Documentation

 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
version: "3.9"
services:

  redis:
    image: redis:alpine
    ports:
      - "6379"
    networks:
      - frontend
    # deploy 需要安装 docker swarm
    deploy:
      replicas: 2
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure

  db:
    image: postgres:9.4
    volumes:
      - db-data:/var/lib/postgresql/data
    networks:
      - backend
    deploy:
      placement:
        max_replicas_per_node: 1
        constraints:
          - "node.role==manager"

  vote:
    image: dockersamples/examplevotingapp_vote:before
    ports:
      - "5000:80"
    networks:
      - frontend
    depends_on:
      - redis
    deploy:
      replicas: 2
      update_config:
        parallelism: 2
      restart_policy:
        condition: on-failure

  result:
    image: dockersamples/examplevotingapp_result:before
    ports:
      - "5001:80"
    networks:
      - backend
    depends_on:
      - db
    deploy:
      replicas: 1
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure

  worker:
    image: dockersamples/examplevotingapp_worker
    networks:
      - frontend
      - backend
    deploy:
      mode: replicated
      replicas: 1
      labels: [APP=VOTING]
      restart_policy:
        condition: on-failure
        delay: 10s
        max_attempts: 3
        window: 120s
      placement:
        constraints:
          - "node.role==manager"

  visualizer:
    image: dockersamples/visualizer:stable
    ports:
      - "8080:8080"
    stop_grace_period: 1m30s
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    deploy:
      placement:
        constraints:
          - "node.role==manager"

networks:
  frontend:
  backend:

volumes:
  db-data:

Linux 安装升级 docker-compose

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# 安装
apt install docker-compose

# 查看安装位置
whereis docker-compose

# 升级
curl -L https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose
chmod 777 /usr/bin/docker-compose

# 测试
docker-compose --version

常用 docker-compose 示例

PostGIS

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
version: '3'

services:
  postgis:
    image : postgis/postgis
    container_name : postgis
    ports :
      - "5432:5432"
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    restart: always
    volumes:
      - /d/docker-data/postgres:/var/lib/postgresql/data

MySQL

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
version: '3'

services:
  mysql:
    image : mysql
    container_name : mysql
    ports :
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=123456
      - MYSQL_DATABASE=postgres
      - MYSQL_USER=postgres
      - MYSQL_PASSWORD=123456
    restart: always
    volumes:
      - /d/docker-data/mysql:/var/lib/mysql

GeoServer

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
version: '3'

services:
  geoserver:
    image : kartoza/geoserver
    container_name : geoserver
    ports :
      - "8090:8080"
    environment:
      - GEOSERVER_ADMIN_USER=admin
      - GEOSERVER_ADMIN_PASSWORD=admin
    restart: always
    volumes:
      - /d/docker-data/geoserver:/opt/geoserver/data_dir

MinIO

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
version: '3'

services:
  minio:
    image: minio/minio
    container_name: minio
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - /d/docker-data/minio:/data
    environment:
      MINIO_ROOT_USER: "minioadmin"
      MINIO_ROOT_PASSWORD: "minioadmin"
    command: server --console-address ":9001" /data

HDFS

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
version: '3'

services:
  hdfs:
    image: pravega/hdfs:2.7.7
    container_name: hdfs
    ports:
      - "22022:22"
      - "8020:8020"
      - "50010:50010"
      - "50020:50020"
      - "50070:50070"
      - "50075:50075"
      - "2049:2049"

ZicSearch

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
version: '3'

services:
  zicsearch:
    image: public.ecr.aws/zinclabs/zincsearch:latest
    container_name: zincsearch
    ports:
      - "4080:4080"
    volumes:
      - /d/docker-data/zincsearch:/data
    environment:
      - ZINC_DATA_PATH=/data
      - ZINC_FIRST_ADMIN_USER=admin
      - ZINC_FIRST_ADMIN_PASSWORD=admin

RustDesk

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
version: '3'

services:
  rustdesk:
    image: rustdesk/rustdesk-server
    ports:
      - "21115:21115"
      - "21116:21116"
      - "21117:21117"
      - "21118:21118"
      - "21119:21119"
    volumes:
      - ./data:/root
    restart: always

PgVector

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Use postgres/example user/password credentials
version: '3.0'

services:
  pgvector:
    image: pgvector/pgvector:pg16
    # restart: always
    environment:
      POSTGRES_PASSWORD: 123456
    volumes:
      - ./data:/var/lib/postgresql/data
    ports:
      - 5433:5432
  

nginx-proxy-manager

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
version: '3'
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt

nebula

  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
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
version: '3.4'
services:
  metad0:
    image: docker.io/vesoft/nebula-metad:nightly
    environment:
      USER: root
    command:
      - --meta_server_addrs=metad0:9559
      - --local_ip=metad0
      - --ws_ip=metad0
      - --port=9559
      - --ws_http_port=19559
      - --data_path=/data/meta
      # - --log_dir=/logs
      # log to stderr not file
      - --logtostderr=true
      - --redirect_stdout=false
      # log to stderr not file
      - --v=0
      - --minloglevel=0
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://metad0:19559/status"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 20s
    ports:
      - 9559:9559
      - 19559:19559
      - 19560
    volumes:
      - ./data/meta0:/data/meta
      # - ./logs/meta0:/logs
    networks:
      - nebula-net
    restart: on-failure
    cap_add:
      - SYS_PTRACE

  storaged0:
    image: docker.io/vesoft/nebula-storaged:nightly
    environment:
      USER: root
    command:
      - --meta_server_addrs=metad0:9559
      - --local_ip=storaged0
      - --ws_ip=storaged0
      - --port=9779
      - --ws_http_port=19779
      - --data_path=/data/storage
      # - --log_dir=/logs
      # log to stderr not file
      - --logtostderr=true
      - --redirect_stdout=false
      # log to stderr not file
      - --v=0
      - --minloglevel=0
    depends_on:
      - metad0
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://storaged0:19779/status"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 20s
    ports:
      - 9779:9779
      - 19779:19779
      - 19780
    volumes:
      - ./data/storage0:/data/storage
      # - ./logs/storage0:/logs
    networks:
      - nebula-net
    restart: on-failure
    cap_add:
      - SYS_PTRACE

  graphd:
    image: docker.io/vesoft/nebula-graphd:nightly
    environment:
      USER: root
    command:
      - --meta_server_addrs=metad0:9559
      - --port=9669
      - --local_ip=graphd
      - --ws_ip=graphd
      - --ws_http_port=19669
      # - --log_dir=/logs
      # log to stderr not file
      - --logtostderr=true
      - --redirect_stdout=false
      # log to stderr not file
      - --v=0
      - --minloglevel=0
    depends_on:
      - storaged0
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://graphd:19669/status"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 20s
    ports:
      - 9669:9669
      - 19669:19669
      - 19670
    # volumes:
    #   - ./logs/graph:/logs
    networks:
      - nebula-net
    restart: on-failure
    cap_add:
      - SYS_PTRACE

  storage-activator:
    # This is just a script to activate storaged for the first time run by calling nebula-console
    # Refer to https://docs.nebula-graph.io/master/4.deployment-and-installation/manage-storage-host/#activate-storaged
    # If you like to call console via docker, run:

    # docker run --rm -ti --network host vesoft/nebula-console:nightly -addr 127.0.0.1 -port 9669 -u root -p nebula

    image: docker.io/vesoft/nebula-console:nightly
    entrypoint: ""
    environment:
      ACTIVATOR_RETRY: ${ACTIVATOR_RETRY:-30}
    command: 
      - sh
      - -c
      - |
        for i in `seq 1 $$ACTIVATOR_RETRY`; do
          nebula-console -addr graphd -port 9669 -u root -p nebula -e 'ADD HOSTS "storaged0":9779' 1>/dev/null 2>/dev/null;
          if [[ $$? == 0 ]]; then
            echo "✔️ Storage activated successfully.";
            break;
          else
            output=$$(nebula-console -addr graphd -port 9669 -u root -p nebula -e 'ADD HOSTS "storaged0":9779' 2>&1);
            if echo "$$output" | grep -q "Existed"; then
              echo "✔️ Storage already activated, Exiting...";
              break;
            fi
          fi;
          if [[ $$i -lt $$ACTIVATOR_RETRY ]]; then
            echo "⏳ Attempting to activate storaged, attempt $$i/$$ACTIVATOR_RETRY... It's normal to take some attempts before storaged is ready. Please wait.";
          else
            echo "❌ Failed to activate storaged after $$ACTIVATOR_RETRY attempts. Please check MetaD, StorageD logs. Or restart the storage-activator service to continue retry.";
            echo "ℹ️ Error during storage activation:"
            echo "=============================================================="
            echo "$$output"
            echo "=============================================================="
            break;
          fi;
          sleep 5;
        done && tail -f /dev/null;        

    depends_on:
      - graphd
    networks:
      - nebula-net

networks:
  nebula-net:

neo4j

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
version: '3.4'

services:
  neo4j:
    image: neo4j:5.23.0
    ports: 
      - 7474:7474
      - 7687:7687
    restart: always
    privileged: true
    environment:
      NEO4J_AUTH: neo4j/12345678
    volumes:
      - ./data:/data

Nginx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
version: '3'

services:
  nginx:
    image: 192.168.9.30/dtd_gis/nginx:1.25
    container_name: nginx
    restart: always
    ports:
      - "10000:80"
      - "10022:10022"
    volumes:
      - ./conf/nginx.conf:/etc/nginx/nginx.conf
      - ./conf/conf.d:/etc/nginx/conf.d
      - ./html:/usr/share/nginx/html
      - /d/data/python_file:/usr/share/nginx/html

Martin

1
2
3
4
5
6
7
8
9
version: '3'

services:
  martin:
    image: ghcr.io/maplibre/martin:latest
    volumes:
      - ./config:/config
    ports:
      - 3000:3000

Hbase

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
version: '3'

services:
  hbase:
    image: harisekhon/hbase:1.3
    ports:
      - "2181:2181"
      - "16000:16000"
      - "16010:16010"
      - "16020:16020"
    environment:
      - ZOOKEEPER_QUORUM=127.0.0.1

Graphhopper

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# docker run -p 8989:8989 -v ./data.pbf:/graphhopper/data.pbf israelhikingmap/graphhopper:9.1 --host 0.0.0.0
version: '3'

services:
  graphhopper:
    image: israelhikingmap/graphhopper:9.1
    ports:
      - "8989:8989"
    volumes:
      - ./config:/graphhopper
      # - ./data:/data
    environment:
      - JAVA_OPTS=-Xmx8g -Xms2g
    command: "-i /graphhopper/data.pbf --host 0.0.0.0 "

Frp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
version: "3.0"

services:
# sudo docker run -d -p 7000:7000 -p 80:80 -p 443:443 -p 7500:7500 -v /data/frps/frps.toml:/etc/frp/frps.toml --name frps snowdreamtech/frps
  frps:
    image: snowdreamtech/frps
    container_name: frps
    ports:
      - "7000:7000"
      - "7080:80"
      - "7500:7500"
    volumes:
      - ./frps.toml:/etc/frp/frps.toml

ElasticSearch

 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
version: '3'

services:
  elasticsearch:
    image: elasticsearch:8.1.0
    container_name: elasticsearch
    restart: unless-stopped
    # volumes:
    #   - "./elasticsearch/data:/usr/share/elasticsearch/data"
    #   - "./elasticsearch/logs:/usr/share/elasticsearch/logs"
    #   - "./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml"
    environment: 
      TZ: Asia/Shanghai
      LANG: en_US.UTF-8
      discovery.type: single-node
      ES_JAVA_OPTS: "-Xmx512m -Xms512m"
      ELASTIC_PASSWORD: "123456"
    ports:
      - "9200:9200"
      - "9300:9300"
    networks:
      - es

  # kibana:
  #   image: registry.cn-hangzhou.aliyuncs.com/zhengqing/kibana:7.14.1       # 原镜像`kibana:7.14.1`
  #   container_name: kibana
  #   restart: unless-stopped
  #   volumes:
  #     - ./elasticsearch/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml
  #   ports:
  #     - "5601:5601"
  #   depends_on:
  #     - elasticsearch
  #   links:
  #     - elasticsearch
  #   networks:
  #     - es

networks:
  es:
    driver: bridge
Licensed under CC BY-NC-SA 4.0
Gear(夕照)的博客。记录开发、生活,以及一些不足为道的思考……