如果部署微服务项目的话,多个服务需要启动,
如果用docker run一个一个启动效率实在是太慢了
可以用docker-compose 一键启动多个服务
第一步:服务打成jar之后每个服务一个文件夹并把Dockerfile加进去
第二步 :编写docker-compose.yml文件
version: '3.8'
services:
sdss-base-gateway:
build:
context: ./sdss-base-gateway
dockerfile: Dockerfile
container_name: sdss-base-gateway
ports:
- "8881:8080"
networks:
- custom-network
sdss-base-auth:
build:
context: ./sdss-base-auth
dockerfile: Dockerfile
container_name: sdss-base-auth
ports:
- "8882:9200"
networks:
- custom-network
sdss-base-biz:
build:
context: ./sdss-base-biz
dockerfile: Dockerfile
container_name: sdss-base-biz
ports:
- "8883:9205"
networks:
- custom-network
sdss-base-file:
build:
context: ./sdss-base-file
dockerfile: Dockerfile
container_name: sdss-base-file
ports:
- "8884:9300"
networks:
- custom-network
sdss-base-gen:
build:
context: ./sdss-base-gen
dockerfile: Dockerfile
container_name: sdss-base-gen
ports:
- "8885:9202"
networks:
- custom-network
sdss-base-job:
build:
context: ./sdss-base-job
dockerfile: Dockerfile
container_name: sdss-base-job
ports:
- "8886:9203"
networks:
- custom-network
sdss-base-system:
build:
context: ./sdss-base-system
dockerfile: Dockerfile
container_name: sdss-base-system
ports:
- "8887:9201"
networks:
- custom-network
sdss-base-workflow:
build:
context: ./sdss-base-workflow
dockerfile: Dockerfile
container_name: sdss-base-workflow
ports:
- "8889:9204"
networks:
- custom-network
networks:
custom-network:
driver: bridge
注意要用docker的网络,这样注册到nacos各个服务之间才可以调通,要不就会调不通服务!!!
第三步:把文件上传到服务器,执行命令
上传到服务器注意docker-compose.yml文件位置要个文件夹在同一目录下
进入目标文件夹下执行命令:docker-compose up --build -d
这些服务就会一键启动啦!!
停的话也简单: docker-compose down 一键停止删除多个容器
标签:compose,network,一键,base,build,docker,sdss,Dockerfile,networks From: https://blog.csdn.net/wangchao6611428/article/details/141214936