Docker安装

Docker:

## 安装Docker
yum remove docker docker-client docker-client-latest docker-common docker-latest \
                  docker-latest-logrotate docker-logrotate docker-engine && \ 
yum install -y yum-utils && \
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo && \
yum install -y docker-ce docker-ce-cli containerd.io

Docker-Compose:

官方文档

  1. 安装
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

要安装不同版本的 Compose,请将 1.29.2 替换为您要使用的 Compose 版本

  1. 授权
## 对二进制文件应用可执行权限
chmod +x /usr/local/bin/docker-compose
## 查看是否安装完成
docker-compose --version
  1. 配置软链(可选)
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Compose案例:

使用docker-compose部署jenkins,nexus3,sonarqube,postgreSql.

  1. docker-compose.yml
version: "3"
services:
   sonarqube:
      image: sonarqube:8.9.2-community
      depends_on:
         - db
      environment:
         SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
         SONAR_JDBC_USERNAME: sonar
         SONAR_JDBC_PASSWORD: sonar
      volumes:
         - sonarqube_data:/opt/sonarqube/data
         - sonarqube_extensions:/opt/sonarqube/extensions
         - sonarqube_logs:/opt/sonarqube/logs
      ports:
         - "9000:9000"
   db:
      image: postgres:12
      environment:
         POSTGRES_USER: sonar
         POSTGRES_PASSWORD: sonar
      volumes:
         - postgresql:/var/lib/postgresql
         - postgresql_data:/var/lib/postgresql/data
      ports:
         - "5432:5432"
   jenkins:
      image: jenkins/jenkins:lts-jdk11
      volumes:
         - jenkins_home:/var/jenkins_home
      ports:
         - "8088:8080"
         - "50000:50000"
      extra_hosts:
         - "gitlab-dev.jinkosolar.com:172.18.2.170"
   nexus:
      image: sonatype/nexus3:3.32.0
      volumes:
         - nexus_data:/nexus-data
      ports:
         - "8081:8081"
         # 这个端口给docker私有仓库使用,在创建仓库时指定,并且在Dockers中需要添加配置 "insecure-registries":["172.18.2.170:5000"]
      - "5000:5000"
volumes:
   sonarqube_data:
   sonarqube_extensions:
   sonarqube_logs:
   postgresql:
   postgresql_data:
   jenkins_home:
   nexus_data:
  1. 启动这些服务

    ## 启动
    docker-compose -f devops/docker-compose.yml  up -d
    
posted @ 2023-02-12 20:17  菜阿  阅读(27)  评论(0编辑  收藏  举报