1、Docker镜像拉取 Jenkins 环境命令
docker pull jenkins/jenkins:lts
查看下拉取的镜像
docker images
2、通过容器编排方式构建 Jenkins 容器
创建对应目录
# 创建对应目录
mkdir -p /data/jenkins/jenkins_home/
chown -R 1000:1000 /data/jenkins/jenkins_home/
+ data
- docker-compose.yml // docker-compose执行文件
+ /data/jenkins
- jenkins_home // Jenkins挂载卷
docker-compose.yml文件配置
version: "3"
services:
jenkins:
user: root
restart: "always"
image: jenkins/jenkins:lts
container_name: jenkins
privileged: true
ports:
- 8080:8080
- 50000:50000
environment:
JAVA_OPTS: -Duser.timezone=Asia/Shanghai
volumes:
- /data/jenkins/jenkins_home/:/var/jenkins_home
- /data/jenkins/workspace/:/root/.jenkins/workspace \
- /usr/local/apache-maven-3.6.0:/usr/local/maven
- /usr/local/maven/maven-3.6.0/repository:/usr/local/maven/repository
- /usr/local/jdk1.8.0_211:/usr/local/jdk
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- /etc/localtime:/etc/localtime
- /usr/local/bin/docker-compose:/usr/local/bin/docker-compose
- /usr/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7
- /root/.ssh:/root/.ssh # (可选)免密配置时,公钥可以直接在本地配置
3、启动容器环境
需要进入 compose 目录下面输入以下命令,进行环境的启动
docker-compose up -d
4、docker-compose 其它操作
镜像内容器进行操作后可以保存成新的镜像,比如容器内安装了jdk、配置了环境变量可以保存为新的镜像