docker install jenkins publish asp.net core 2.0

Installation Docker

  In fact, the process of installing Docker, we can go to the Docker 's official website to find their corresponding installation documentation for installation, Docker differentiate between the two versions of CE and EE, specifically the two versions What is the difference, everyone access to relevant information on their own, no longer outlined here . Tutorials are using CE then find the corresponding official document installation , the following steps of the tutorial is installed

  1. Update package about it, and more and more harmless

# sudo yum -y update

 

  2. Install the required packages 

# sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

 

3. Use the stable version of the warehouse (of course you can use the latest version or beta version of the warehouse, the need for official description)

# sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

 

4. Installation Docker ce 

# sudo yum install docker-ce

tips: on a production system, you should install a specific version of Docker CE, rather than always using the latest version.

 

5. Start Docker

# sudo systemctl start docker

 

6. dockerBy running hello-world verify correct installation image.

# docker run hello-world

If the following screen appears, on behalf of the installation is successful

 

Installation Jenkins

  First, not directly from Docker Store directly Pull Jenkins of Image files will need to be because Docker automatic deployment dotnet core, the need for Docker on the host operating directly, you need to mount Docker Jenkins Image, so it needs its own Dockerfile start writing custom build Jenkins.

  

# touch Dockerfile
# vim Dockerfile

Insert the following:

Copy the code
Jenkins the FROM 

the USER the root 
# Clear the source base image set, switched to Tencent cloud jessie source 
# Tencent need to use a non-cloud environment will tencentyun to aliyun 
the RUN echo ''> /etc/apt/sources.list.d/jessie -backports.list \ 
  && echo "deb http://mirrors.aliyun.com/debian Jessie main contrib non-as Free"> /etc/apt/sources.list \ 
  && echo "deb http://mirrors.aliyun.com / Debian Jessie-the Updates main contrib non-as Free ">> /etc/apt/sources.list \ 
  && echo" deb http://mirrors.aliyun.com/debian-security Jessie / the Updates main contrib non-as Free ">> /etc/apt/sources.list 
# update source and install the missing packet 
the RUN APT-APT-GET GET update && && the install -Y libltdl7 APT-GET update 

ARG dockerGid = 999 

the RUN echo "Docker: X: $ {} dockerGid: jenkins ">> /etc/group 
>> / etc / Group 
# mounted docker-compose because the needs of the environment and so constructed
RUN curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

RUN chmod +x /usr/local/bin/docker-compose
Copy the code

If you do not install libltdl7 will result in the following problem, because the internal container do not have this package jenkins

docker: error while loading shared libraries: libltdl.so.7: cannot open shared object file: No such file or directory
Build step 'Execute shell' marked build as failure

The problem occurs when Jenkins denied access to the host operating Docker, in fact, jenkins user does not have access docker container command outside of the container, so the RUN command requires the user to the Docker Jenkins User Group

 

Image building

# docker build . -t auto-jenkins

Successfully appear above content represents the installation successfully Jenkins

 

Jenkins at startup, you need to create a configuration directory Jenkins, and mount to the next docker in the Jenkins directory

# mkdir -p /var/jenkins_home

Run Jenkins

# docker run --name jenkins -p 8080:8080 -p 50000:50000 \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v $(which docker):/bin/docker \
    -v /var/jenkins_home :/var/jenkins_home \
    -d auto-jenkins

 

  第一行:构建一个名称为jenkins的容器  -p 是容器运行开放端口

  第二行 和第三行: -v 是将宿主机的docker文件挂载进容器里

  第四行:建立宿主机的配置目录,挂载进docker容器里,这样容器里的Jenkins配置目录文件就会映射出来

       第五行:使用auto-jenkins Image 并且后台启动

这个时候 run Jenkins 会提示成功

执行 docker ps 命令后,发现什么都没有

执行 docker ps -a 命令看看

 

执行 docker start -a jenkins 让容器前台输出运行信息的方式运行

不难看出其实 Jenkins 启动已经是可以了,只是权限问题导致这个错误的信息。

 

现在需要看一下Jenkins官方的Dockerfile 

 知道问题原因,贴上代码了。

##修改 /var/jenkins 文件夹权限
# chown -R 1000 /var/jenkins_home

 继续执行运行Jenkins 代码

# docker run --name jenkins -p 8080:8080 -p 50000:50000 \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v $(which docker):/bin/docker \
    -v /var/jenkins_home:/var/jenkins_home \
    -d auto-jenkins

出现一串字符后,执行 docker ps 会发现容器已经启动了,正常了。这个时候是不是可以使用了?别着急,还有很长的路。

 

配置Jenkins

打开浏览器输入地址 your IP:8080 进行访问,你会开心的看到这个界面,看到这个界面代表你的Jenkins 已经安装成功了,但是需要进行配置,现在就教大家怎么去配置

 

首先,进入容器内

# docker exec -it jenkins /bin/bash

查看 /var/jenkins_home/secrets/initialAdminPassword 文件内的密码

# cat /var/jenkins_home/secrets/initialAdminPassword

其实不一定要进入容器内查看密码,可以直接在宿主机的环境下,查看 /var/jenkins//secrets/initialAdminPassword 的内容,因为之前笔者已经将这个目录挂载进Docker里面了

 

复制输出的内容,粘贴到Administrator password,输入 exit 退出容器,此时进行下一步你会看到此界面,点击 Install suggested plugins

 

等待初始化完毕 

 

到了这一步,自己随缘去填吧。

 

使用VS2017创建一个ASP.NET Core 2.0 Web应用程序,并将代码上传到git。这里笔者就不演示上传代码的过程步骤了。

为你们准备了一个地址,方便你们完成本教程:http://git.oschina.net/wenalu/MvcTest

 

新建一个自由风格的软件项目,并填名称 点击 OK

 

填写源代码管理

 

勾选 Poll SCM 设置拉取Git 上代码的间隔,笔者这里是两分钟拉取一次

 

勾上 Delete workspace before build start 是设置构建前删除工作区

勾上 Abort the build if it's stuck 是设定构建的超时时间,如果构建使用的时间超过设定的时间,那么就认为这次的构建是失败的。笔者这里超时设置的是10分钟

 

增加一个Execute Shell 脚本,并填写以下脚本内容

Copy the code
#!/bin/bash
# 获取短版本号

GITHASH=`git rev-parse --short HEAD`
echo ---------------Remove-Orphans------------------
docker-compose -f ./docker-compose.yml -f ./docker-compose.override.yml  -p dockercompose4255153253317384266 down --rmi local --remove-orphans
echo ------------------Config-----------------------
docker-compose -f ./docker-compose.ci.build.yml -p dockercompose4255153253317384266 config
echo ------------------Build------------------------
docker-compose -f ./docker-compose.ci.build.yml -p dockercompose4255153253317384266 up --build
echo ---------------Publishing...------------------
docker-compose -f "./docker-compose.yml" -f "./docker-compose.override.yml"  -p dockercompose4255153253317384266 up -d --build
Copy the code

 

Apply to save and return to the project interface. Click immediately work to build deployment SUCCESS

 

Open your browser and enter the address of your IP: 8088 /

Reference address

https://www.cnblogs.com/LongJiangXie/p/7517909.html Centos7 & Docker & Jenkins & ASP.NET Core 2.0 release and deployment automation
https://www.cnblogs.com/stulzq/p/8627360.html use Docker installation Jenkins
https://www.cnblogs.com/stulzq/p/8627824.html ASP.NET Core + + Docker Jenkins achieve continuous integration

[Jenkins] admin user login, invalid login prompt (before landing OK, three days without landing, landing suddenly prompted invalid, restarting can not solve) the solution to
the problem phenomenon:

The system has been normal, suddenly one day landing, suggesting Invalid user to log in successfully.


1, open the config file, JENKINS_HOME directory, and then look for config.xml file in the directory)

2、修改<useSecurity>true</useSecurity>为<useSecurity>false</useSecurity>

3, delete <authorizationStrategy> ***** </ authorizationStrategy> and <securityRealm> **** </ securityRealm> two elements

4, restart jenkins, you can re-login

 

 

Guess you like

Origin www.cnblogs.com/yxlblogs/p/11680791.html