环境

  • linux centos 7.6
  • Docker version 24.0.5, build ced0996

安装 docker-compose

1.打开下载页面:
https://github.com/docker/compose/releases

2.下载 docker-compose-linux-x86_64 v2.20.2

wget https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-linux-x86_64
mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose

3.赋权:
[root@localhost ~]# chmod +x /usr/local/bin/docker-compose

4.看版本: 就是一个二进制文件.用它去运行命令
[root@localhost ~]# docker-compose version
Docker Compose version v2.20.2

[root@localhost /usr/local/bin]# docker -v
Docker version 24.0.5, build f480fb1

5.卸载:
[root@localhost bin]# rm /usr/local/bin/docker-compose
rm:是否删除普通文件 “/usr/local/bin/docker-compose”?y
[root@localhost bin]# docker-compose version
-bash: /usr/local/bin/docker-compose: 没有那个文件或目录

例一

新建 docker-compose

  1. vim docker-compose

  2. 内容

version: '3.8'
services:
  go-admin-api:
    container_name: go-admin
    image: go-admin:latest
    privileged: true
    restart: always
    ports:
      - 8000:8000
    volumes:
      - ./config/:/go-admin-api/config/
      - ./static/:/go-admin-api/static/
      - ./temp/:/go-admin-api/temp/
    #command: --gf.gcfg.file=/app/config/config.yaml # 这里写容器内的配置路径
    command: /go-admin-api/go-admin-api -c=config/settings.dev.93.yml # 这里写容器内的配置路径
    network_mode: host # 使用network_mode:host模式,上面的ports端口映射会失效
    #networks:
    #  - myweb
#networks:
#  myweb:
#    driver: bridge

启动

docker-compose up -d

停止

docker-compose down

例二

version: '3.8'
services:
  offline-map-api:
    container_name: offlinemap
    image: 10.10.11.145:8082/512cert/offlinemap:main-V1.0.0
    privileged: true
    restart: always
    ports:
      - 88:80
    volumes:
      # 宿主机的地址:容器内的地址
      - ./scripts/nginx/api_proxy.conf:/etc/nginx/conf.d/api_proxy.conf
    networks:
      - myweb
networks:
  myweb:
    driver: bridge
作者:海马  创建时间:2023-05-07 07:35
最后编辑:海马  更新时间:2024-08-03 21:41