docker-compose安装Jenkins遇到的问题

原因: 数据库和Jenkins分开部署,采用docker-compose一键部署即可

1、docker-compose脚本如下:

[root@jenkins-98 /data]# cat docker-compose.yml 
version: '3.3'
services: 
  jenkins:  
    image: jenkins/jenkins:lts
    restart: always
    depends_on:
      - postgresql
    ports:
      - "8080:8080"
      - "50000:50000"
    volumes:
      - '/data/jenkins_home:/var/jenkins_home'
      - '/data/server:/data/server'
      - '/data/jdk:/data/jdk'
    environment:
      - TZ=Asia/Shanghai
      - JAVA_OPTS=-Duser.timezone=Asia/Shanghai

  postgresql:
    restart: always
    image: sameersbn/postgresql:10-2
    volumes:
      - ./postgresql-data:/var/lib/postgresql:Z
    environment:
      - DB_USER=jenkins
      - DB_PASS=jenkins-password
      - DB_NAME=jenkins
      - DB_EXTENSION=pg_trgm

2、安装docker-ce

# 1、安装依赖包
yum install -y yum-utils device-mapper-persistent-data lvm2

# 2、安装docker的镜像仓库
## 官方源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

## 国内镜像源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 安装docker-ce
yum install docker-ce

【默认安装的存储路径为 /var/lib/docker】此处修改存储路径有2种方式,假设新的存储路径为 /data/docker

# 1、软链方式
mkdir  -pv /data/docker
ln -s /data/docker  /var/lib/docker

# 启动
systemctl start docker
systemctl enable docker

# 2、修改配置文件的存储路径,在EXECStart的后面增加后如下:
vim /usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd --graph /data/docker

# 重启生效
systemctl restart docker
systemctl enable docker

# 查看docker信息
docker info
---------
Docker Root Dir: /data/docker
---------

2-1、安装docker-compose

yum -y install docker-compose

3、在同目录下启动

 docker-compose up -d

问题:发现数据库没起来,docker logs docker-name 查看报错信息

‣ Setting postgresql.conf parameter: data_directory = '/var/lib/postgresql/10/main'
sudo: error in /etc/sudo.conf, line 0 while loading plugin "sudoers_policy"
sudo: /usr/lib/sudo/sudoers.so must be owned by uid 0
sudo: fatal error, unable to load plugins
Initializing datadir...
Initializing certdir...
Initializing logdir...
Initializing rundir...
Setting resolv.conf ACLs...

解决: 权限问题,给sudoers.so文件赋权 644 root

# 查找docker内此文件的路径
[root@jenkins-98 jenkins]# find /data/docker -name 'sudoers.so' 
/data/docker/overlay2/b85191d400284e1c8436908831975cdfe903c48b69efc3391e678993e69b5cd3/diff/usr/lib/sudo/sudoers.so
/data/docker/overlay2/bdf0c1abedf591ad6cfdf3828aacb7113b96eb2f0613aad452ac82988c0772f8/merged/usr/lib/sudo/sudoers.so

# 赋权
chmod 644 /data/docker/overlay2/b85191d400284e1c8436908831975cdfe903c48b69efc3391e678993e69b5cd3/diff/usr/lib/sudo/sudoers.so

chown -R root /data/docker/overlay2/b85191d400284e1c8436908831975cdfe903c48b69efc3391e678993e69b5cd3/diff/usr/lib/sudo

 

你可能感兴趣的:(jenkins,docker)