Docker 安装Jenkins

SunnyFan小于 1 分钟约 296 字

Docker 安装Jenkins

docker安装jenkins - hanease - 博客园 (cnblogs.com)open in new window

配置 Docker 镜像

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io

Docker拉取镜像

docker pull jenkins/jenkins:lts

配置本地存储目录

mkdir -p /apps/devops/jenkins
chmod 777 /apps/devops/jenkins

启动Jenkins容器

docker stop jenkins
docker rmi jenkins

sudo usermod -a -G docker root
sudo chmod 666 /var/run/docker.sock


docker run -itd -p 9003:8080 -p 9004:50000 \
--restart always \
-v /apps/devops/jenkins:/var/jenkins_home \
--name jenkins \
--volume /var/run/docker.sock:/var/run/docker.sock \
-v $(which docker):/usr/bin/docker \
-v $(which docker):/usr/bin/com.docker.cli \
jenkins/jenkins:lts

Docker 运行aspnetcore项目

docker run -it -d -p 7000:80 --name aspnetcoredemo aspnetcoredemo

构建项目

docker build -f src/aspnetcoredemo/Dockerfile -t aspnetcoredemo .

GITHASH=`git rev-parse --short HEAD`
docker build -f src/aspnetcoredemo/Dockerfile -t aspnetcoredemo:$GITHASH .
docker tag aspnetcoredemo:$GITHASH aspnetcoredemo:latest

docker build -f src/Services/ToDo/IGeekFan.FreeKit.Todos.API/Dockerfile -t igeekfan.freekit.todos.api .
  

aspnetcoredemo项目 bash脚本

#!/bin/bash
# 获取短版本号
GITHASH=`git rev-parse --short HEAD`
docker stop aspnetcoredemo
docker rm aspnetcoredemo
echo ---------------Building Docker Image..aspnetcoredemo.------------------
docker build -f src/aspnetcoredemo/Dockerfile -t aspnetcoredemo:$GITHASH .
docker tag aspnetcoredemo:$GITHASH aspnetcoredemo:latest
echo ---------------Launching Container..aspnetcoredemo.------------------
docker run -it -d -p 7000:80 --name aspnetcoredemo aspnetcoredemo -v 

echo ---------------Finish..aspnetcoredemo.------------------

docker stop webapplicationdemo
docker rm webapplicationdemo
echo ---------------Building Docker Image..webapplicationdemo.------------------
docker build -f src/webapplicationdemo/Dockerfile -t webapplicationdemo:$GITHASH .
docker tag webapplicationdemo:$GITHASH webapplicationdemo:latest
echo ---------------Launching Container..webapplicationdemo.------------------
docker run -it -d -p 7001:80 --name webapplicationdemo webapplicationdemo -v