#使用docker安装jenkins
镜像地址
docker镜像配置文档
#拉取镜像
docker pull jenkins/jenkins
docker run -d
-p 18081:8080 -p 50000:50000
#数据文件挂载
-v /usr/local/use_data/jenkins/data:/var/jenkins_home
#时间同步
-v /etc/localtime:/etc/localtime --name jenkins_01
jenkins/jenkins:latest
注意事项:可能会出现的错误
WARNING: IPv4 forwarding is disabled. Networking will not work.
解决方法:
vim /etc/sysctl.conf
#配置转发
net.ipv4.ip_forward=1
#重启服务,让配置生效
systemctl restart network
#查看是否成功,如果返回为“net.ipv4.ip_forward = 1”则表示成功
sysctl net.ipv4.ip_forward
touch: cannot touch ‘/var/jenkins_home/copy_reference_file.log’: Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
解决方法:
需要修改下目录权限, 因为当映射本地数据卷时,/usr/local/use_data/jenkins目录的拥有者为root用户,而容器中jenkins user的uid为1000
执行如下命令即可:
chown -R 1000:1000 /usr/local/use_data/jenkins
建议:在运行容器前先配合好
关闭防火墙
# CentOS7环境
# 临时关闭
systemctl stop firewalld
# 禁止开机启动
systemctl disable firewalld
访问路径:http://192.168.xxx.xxx:18081
获取登录密码
#进入jenkins容器
docker exec -it 容器id /bin/bash
#查看密匙
cat /var/jenkins_home/secrets/initialAdminPassword
登录界面
选择安装推荐插件
新建一个管理员账户
如果在安装的时候有些组件安装失败,可以后续根据页面上提示的插件,重新安装
**Manage Jenkins(**系统管理) -> Manage Plugins(插件管理) -> available(可选插件)
搜索插件然后安装,最后重启jenkins
maven的settings.xml配置信息
使用docker cp放进容器中
#从主机复制到容器
sudo docker cp settings.xml containerID:container_path
因为JDK是自动安装的,而Oracle的JDK需要登录才能下载,所以会出现以下错误
点击Your Oracle account doesn't appear valid. Please specify a valid username/password
这个链接
这里给出pom.xml
文件
<properties>
<maven.build.timestamp.format>yyyyMMddHHmmssmaven.build.timestamp.format>
<dockerRegistryUrl>192.168.25.142:8090dockerRegistryUrl>
<dockerHost>http://192.168.25.142:2375dockerHost>
<dockerProjectPrefix>taco-clouddockerProjectPrefix>
properties>
<distributionManagement>
<repository>
<id>releasesid>
<url>http://192.168.25.1:18100/nexus/content/repositories/releases/url>
repository>
<snapshotRepository>
<id>snapshotsid>
<url>http://192.168.25.1:18100/nexus/content/repositories/snapshots/url>
snapshotRepository>
distributionManagement>
<build>
<resources>
<resource>
<directory>src/main/resourcesdirectory>
<filtering>truefiltering>
resource>
resources>
<finalName>appfinalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojogroupId>
<artifactId>build-helper-maven-pluginartifactId>
<version>3.0.0version>
<executions>
<execution>
<id>timestamp-propertyid>
<goals>
<goal>timestamp-propertygoal>
goals>
execution>
executions>
<configuration>
<name>current.timename>
<pattern>yyyyMMddHHmmsspattern>
<timeZone>GMT+8timeZone>
configuration>
plugin>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
<plugin>
<groupId>com.spotifygroupId>
<artifactId>docker-maven-pluginartifactId>
<version>0.4.13version>
<configuration>
<serverId>docker-reposerverId>
<forceTags>trueforceTags>
<pushImage>truepushImage>
<imageName>${dockerRegistryUrl}/${dockerProjectPrefix}/${project.artifactId}-${maven.build.timestamp}:${project.version}imageName>
<baseImage>jdk1.8baseImage>
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]entryPoint>
<resources>
<resource>
<targetPath>/targetPath>
<directory>${project.build.directory}directory>
<include>${project.build.finalName}.jarinclude>
resource>
resources>
<dockerHost>${dockerHost}dockerHost>
<registryUrl>${dockerRegistryUrl}registryUrl>
configuration>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-resources-pluginartifactId>
<version>3.1.0version>
<configuration>
<delimiters>
<delimit>$delimit>
delimiters>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>jksnonFilteredFileExtension>
nonFilteredFileExtensions>
configuration>
plugin>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<version>${spring-boot.version}version>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-surefire-pluginartifactId>
<version>${maven-surefire-plugin.version}version>
<configuration>
<skipTests>trueskipTests>
configuration>
plugin>
plugins>
build>
Maven的settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/usr/local/maven/repositorylocalRepository>
<pluginGroups>
<pluginGroup>com.spotifypluginGroup>
pluginGroups>
<proxies>
proxies>
<server>
<id>releasesid>
<username>adminusername>
<password>admin123password>
server>
<server>
<id>snapshotsid>
<username>adminusername>
<password>admin123password>
server>
<server>
<id>docker-repoid>
<username>taco-userusername>
<password>Ha.123456password>
<configuration>
<email>[email protected]email>
configuration>
server>
servers>
<mirrors>
<mirror>
<id>alimavenid>
<name>aliyun mavenname>
<url>http://maven.aliyun.com/nexus/content/groups/public/url>
<mirrorOf>centralmirrorOf>
mirror>
mirrors>
<profiles>
<profile>
<id>JDK-1.8id>
<activation>
<activeByDefault>trueactiveByDefault>
<jdk>1.8jdk>
activation>
<properties>
<maven.compiler.source>1.8maven.compiler.source>
<maven.compiler.target>1.8maven.compiler.target>
<maven.compiler.compilerVersion>1.8maven.compiler.compilerVersion>
properties>
profile>
<profile>
<id>devid>
<repositories>
<repository>
<id>nexusid>
<url>http://localhost:18100/nexus/content/groups/public/url>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>trueenabled>
snapshots>
repository>
repositories>
<pluginRepositories>
<pluginRepository>
<id>publicid>
<name>Public Repositoriesname>
<url>http://localhost:18100/nexus/content/groups/public/url>
pluginRepository>
pluginRepositories>
profile>
profiles>
<activeProfiles>
<activeProfile>devactiveProfile>
activeProfiles>
settings>
本地Maven仓库文件夹没有权限提示错误
#进入docker 容器
docker exec -it -u root ${containId} /bin/bash
#赋予权限
chmod +rw ./repository
推荐直接安装在centos系统中,原因: