docker-compose编排服务

安装

方案一(错误多)

安装docker-compose
yum -y install epel-release
yum -y install python-pip
pip install docker-compose
查看安装版本 docker-compose --version
卸载docker-compose
pip uninstall docker-compose

方案二(慢)

1 下载1.25.0 docker compose
sudo curl -L “https://github.com/docker/compose/releases/download/1.25.0/docker-compose- ( u n a m e − s ) − (uname -s)- (uname−s)−(uname -m)” -o /usr/local/bin/docker-compose
2 添加可执行权限
sudo chmod +x /usr/local/bin/docker-compose
3 测试安装
sudo docker-compose --version

方案三(可行)

1 安装
https://yq.aliyun.com/articles/708974
2 解决命令不存在的问题
https://blog.csdn.net/u012322399/article/details/102756773

docker-compose案例

1 docker-compose.yml文件内容

version: '3'
services:
    ci_demo:
      container_name:
        ci_demo
      build:
       /usr/local/app/
      image:
        'ci-demo:latest'
      ports:
        - "8080:8080"
      volumes:
        - /usr/local/java/jdk1.8.0_231:/usr/local/jdk
        - /usr/local/maven/apache-maven-3.3.9:/usr/local/maven
      environment:
        TZ: 'Asia/Shanghai'
      command:
        java -jar app.jar
      restart: 
        always
    gitlab_gitlab_ce:
      container_name:
        gitlab_gitlab_ce
      image:
        'gitlab/gitlab-ce:latest'
      ports:
         - "443:443"
         - "3030:3030"
         - "2222:22"
      volumes:
        - /usr/local/gitlab/config:/etc/gitlab
        - /usr/local/gitlab/logs:/var/log/gitlab
        - /usr/local/gitlab/data:/var/opt/gitlab
      environment:
        TZ: 'Asia/Shanghai'
      restart:
        always
    sonatype_nexus3:
      container_name:
         sonatype_nexus3
      image:
         'sonatype/nexus3:latest'
      ports:
          - "9001:8081"
      volumes:
         - /usr/local/nexus-data:/nexus-data
      environment:
         TZ: 'Asia/Shanghai'
      restart:
         always
    registry:
      container_name:
          registry
      privileged:
        true
      image:
        'registry:latest'
      ports:
        - "5000:5000"
      volumes:
        - /usr/local/registry:/var/lib/registry
      environment:
        TZ: 'Asia/Shanghai'
      restart:
       always

简要解释:
version: ‘3’ 版本
services: 服务列表
ci_demo: 自定义服务名称
container_name:
ci_demo 自定义容器名称
build:
/usr/local/app/ 构建目录
image:
‘ci-demo:latest’ 使用镜像
ports:
- “8080:8080” 挂载端口
volumes:
- /usr/local/java/jdk1.8.0_231:/usr/local/jdk 挂载目录
- /usr/local/maven/apache-maven-3.3.9:/usr/local/maven
environment:
TZ: ‘Asia/Shanghai’ 时区
command:
java -jar app.jar 容器命令,会替换容器默认命令
restart:
always 重启机制

2 常用命令
docker-compose build 构建
docker-compose up [-d] 启动/更新服务[后台运行]
docker-compose down 停止服务
docker-compose start/restart 启动/重启服务
docker-compose stop 停止服务

start/restart stop 使用docker-compose已经生成的容器进行启动/停止服务,停止服务不会删除容器。docker-compose内容变动不会重新更新容器;
up/down 会生成镜像/删除镜像,docker-compose内容变动会重新更新容器;

总结

此博客实现从docker管理服务,转变从dockers-compose编排管理多个服务

TODO 尚未实现使用jekins集成docker-compose,自动构建,部署服务,CI!!!

上一篇:后端技术:SpringBoot配置热加载工具(devtools)笔记


下一篇:https://blog.csdn.net/weixin_45524582/article/details/102793825