一、官网简介使用安装说明:
How to use this image
docker run -p 8080:8080 -p 50000:50000 jenkins
This will store the workspace in /var/jenkins_home. All Jenkins data lives in there - including plugins and configuration. You will probably want to make that a persistent volume (recommended):
docker run -p 8080:8080 -p 50000:50000 -v /your/home:/var/jenkins_home jenkins
This will store the jenkins data in /your/home on the host. Ensure that /your/home is accessible by the jenkins user in container (jenkins user - uid 1000) or use -u some_other_user parameter with docker run.
You can also use a volume container:
docker run --name myjenkins -p 8080:8080 -p 50000:50000 -v /var/jenkins_home jenkins
Then myjenkins container has the volume (please do read about docker volume handling to find out more).
Passing JVM parameters
You might need to customize the JVM running Jenkins, typically to pass system properties or tweak heap memory settings. Use JAVA_OPTS environment variable for this purpose :
docker run --name myjenkins -p 8080:8080 -p 50000:50000 --env JAVA_OPTS=-Dhudson.footerURL=http://mycompany.com jenkins
Configuring logging
Jenkins logging can be configured through a properties file and java.util.logging.config.file Java property. For example:
mkdir data
cat > data/log.properties <<EOF
handlers=java.util.logging.ConsoleHandler
jenkins.level=FINEST
java.util.logging.ConsoleHandler.level=FINEST
EOF
docker run --name myjenkins -p 8080:8080 -p 50000:50000 --env JAVA_OPTS="-Djava.util.logging.config.file=/var/jenkins_home/log.properties" -v `pwd`/data:/var/jenkins_home jenkins
二、通过自定义,docker进行一行命令启动说明解释
docker run --name myjenkins -d -p 5003:8080 -p 50000:50000 --restart always --privileged=true --user root --env JAVA_OPTS="-Xmx8192m" -v $(pwd)/jenkins_data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -v /bin/docker:/bin/docker --network mybridge jenkins/jenkins:lts
参数的解释:
- docker run: Docker的命令,用于运行一个新的容器。
- –name myjenkins: 为容器指定一个名称myjenkins,这样你可以通过名称而不是容器ID来引用它。
- -d: 以“分离模式”运行容器,即容器在后台运行,不会占用当前的终端会话。
- -p 5003:8080: 将容器内的8080端口映射到宿主机的5003端口上,这样你就可以通过访问宿主机的5003端口来访问Jenkins的Web界面。
- -p 50000:50000: 将容器内的50000端口映射到宿主机的50000端口上,这是Jenkins用于与代理(slaves/agents)通信的端口。
- –restart always: 设置容器的重启策略为“总是重启”。这意味着如果容器停止(无论是由于错误、维护还是Docker守护进程重启),它都会自动重新启动。
- –privileged