环境信息
虚拟机:appserver
说明
现有启动参数
$ docker run \
-d -p 8099:8080 -p 50099:50000 \
-v /appdata/jenkins:/var/jenkins_home \
--name jenkins \
jenkins/jenkins:2.346.3-2-jdk8
调整后启动参数
# docker启动Jenkins
$ docker run \
-v /appdata/jenkins:/var/jenkins_home \
-v /usr/bin/docker:/usr/bin/docker \
-v /var/run/docker.sock:/var/run/docker.sock \
-u root \
-d --name jenkins \
-p 8099:8080 -p 50099:50000 \
jenkins/jenkins:2.346.3-2-jdk8
新增参数说明
挂载宿主机docker-cli、docker.sock到Jenkins中
- 宿主机docker-cli路径/usr/bin/docker
- 宿主机docker.sock路径/var/run/docker.sock
docker修改挂载路径
配置文件位置
$ systemctl stop docker
$ systemctl stop docker.socket
$ cd /var/lib/docker/containers
$ ls -al |grep 8685eaddcd52 # 8685eaddcd52为容器id,获得容器完整路径
drwx--x---. 4 root root 273 May 1 06:39 8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900
$ cd 8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900
$ ls -al
total 2416
drwx--x---. 4 root root 4096 May 3 17:13 .
drwx--x---. 9 root root 4096 May 3 16:50 ..
-rw-r-----. 1 root root 2425836 May 3 17:14 8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900-json.log
drwx------. 2 root root 6 Oct 7 2022 checkpoints
-rw------- 1 root root 4664 May 3 17:13 config.v2.json
-rw-r--r-- 1 root root 1601 May 3 17:13 hostconfig.json
-rw-r--r--. 1 root root 13 May 3 17:13 hostname
-rw-r--r--. 1 root root 174 May 3 17:13 hosts
drwx--x---. 2 root root 6 Oct 7 2022 mounts
-rw-r--r--. 1 root root 54 May 3 17:13 resolv.conf
-rw-r--r-- 1 root root 71 May 3 17:13 resolv.conf.hash
修改配置文件hostconfig.json
$ cp hostconfig.json hostconfig.json.bak
$ vi hostconfig.json
修改前:
关键点
“Binds”:[“/appdata/jenkins:/var/jenkins_home”]
完整版
{"Binds":["/appdata/jenkins:/var/jenkins_home"],"ContainerIDFile":"","LogConfig":{"Type":"json-file","Config":{}},"NetworkMode":"default","PortBindings":{"50000/tcp":[{"HostIp":"","HostPort":"50099"}],"8080/tcp":[{"HostIp":"","HostPort":"8099"}]},"RestartPolicy":{"Name":"always","MaximumRetryCount":0},"AutoRemove":false,"VolumeDriver":"","VolumesFrom":null,"CapAdd":null,"CapDrop":null,"CgroupnsMode":"host","Dns":[],"DnsOptions":[],"DnsSearch":[],"ExtraHosts":null,"GroupAdd":null,"IpcMode":"private","Cgroup":"","Links":null,"OomScoreAdj":0,"PidMode":"","Privileged":false,"PublishAllPorts":false,"ReadonlyRootfs":false,"SecurityOpt":null,"UTSMode":"","UsernsMode":"","ShmSize":67108864,"Runtime":"runc","ConsoleSize":[0,0],"Isolation":"","CpuShares":0,"Memory":0,"NanoCpus":0,"CgroupParent":"","BlkioWeight":0,"BlkioWeightDevice":[],"BlkioDeviceReadBps":null,"BlkioDeviceWriteBps":null,"BlkioDeviceReadIOps":null,"BlkioDeviceWriteIOps":null,"CpuPeriod":0,"CpuQuota":0,"CpuRealtimePeriod":0,"CpuRealtimeRuntime":0,"CpusetCpus":"","CpusetMems":"","Devices":[],"DeviceCgroupRules":null,"DeviceRequests":null,"KernelMemory":0,"KernelMemoryTCP":0,"MemoryReservation":0,"MemorySwap":0,"MemorySwappiness":null,"OomKillDisable":false,"PidsLimit":null,"Ulimits":null,"CpuCount":0,"CpuPercent":0,"IOMaximumIOps":0,"IOMaximumBandwidth":0,"MaskedPaths":["/proc/asound","/proc/acpi","/proc/kcore","/proc/keys","/proc/latency_stats","/proc/timer_list","/proc/timer_stats","/proc/sched_debug","/proc/scsi","/sys/firmware"],"ReadonlyPaths":["/proc/bus","/proc/fs","/proc/irq","/proc/sys","/proc/sysrq-trigger"]}
修改后:
关键点
“Binds”:[“/appdata/jenkins:/var/jenkins_home”,“/usr/bin/docker:/usr/bin/docker”,“/var/run/docker.sock:/var/run/docker.sock”]
完整版
{"Binds":["/appdata/jenkins:/var/jenkins_home","/usr/bin/docker:/usr/bin/docker","/var/run/docker.sock:/var/run/docker.sock"],"ContainerIDFile":"","LogConfig":{"Type":"json-file","Config":{}},"NetworkMode":"default","PortBindings":{"50000/tcp":[{"HostIp":"","HostPort":"50099"}],"8080/tcp":[{"HostIp":"","HostPort":"8099"}]},"RestartPolicy":{"Name":"always","MaximumRetryCount":0},"AutoRemove":false,"VolumeDriver":"","VolumesFrom":null,"CapAdd":null,"CapDrop":null,"CgroupnsMode":"host","Dns":[],"DnsOptions":[],"DnsSearch":[],"ExtraHosts":null,"GroupAdd":null,"IpcMode":"private","Cgroup":"","Links":null,"OomScoreAdj":0,"PidMode":"","Privileged":false,"PublishAllPorts":false,"ReadonlyRootfs":false,"SecurityOpt":null,"UTSMode":"","UsernsMode":"","ShmSize":67108864,"Runtime":"runc","ConsoleSize":[0,0],"Isolation":"","CpuShares":0,"Memory":0,"NanoCpus":0,"CgroupParent":"","BlkioWeight":0,"BlkioWeightDevice":[],"BlkioDeviceReadBps":null,"BlkioDeviceWriteBps":null,"BlkioDeviceReadIOps":null,"BlkioDeviceWriteIOps":null,"CpuPeriod":0,"CpuQuota":0,"CpuRealtimePeriod":0,"CpuRealtimeRuntime":0,"CpusetCpus":"","CpusetMems":"","Devices":[],"DeviceCgroupRules":null,"DeviceRequests":null,"KernelMemory":0,"KernelMemoryTCP":0,"MemoryReservation":0,"MemorySwap":0,"MemorySwappiness":null,"OomKillDisable":false,"PidsLimit":null,"Ulimits":null,"CpuCount":0,"CpuPercent":0,"IOMaximumIOps":0,"IOMaximumBandwidth":0,"MaskedPaths":["/proc/asound","/proc/acpi","/proc/kcore","/proc/keys","/proc/latency_stats","/proc/timer_list","/proc/timer_stats","/proc/sched_debug","/proc/scsi","/sys/firmware"],"ReadonlyPaths":["/proc/bus","/proc/fs","/proc/irq","/proc/sys","/proc/sysrq-trigger"]}
修改配置文件config.v2.json
$ cp config.v2.json config.v2.json.bak
$ vi config.v2.json
修改前:
关键内容
"MountPoints": {
"/var/jenkins_home": {
"Source": "/appdata/jenkins",
"Destination": "/var/jenkins_home",
"RW": true,
"Name": "",
"Driver": "",
"Type": "bind",
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "/appdata/jenkins",
"Target": "/var/jenkins_home"
},
"SkipMountpointCreation": false
}
}
完整版
{"StreamConfig":{},"State":{"Running":false,"Paused":false,"Restarting":false,"OOMKilled":false,"RemovalInProgress":false,"Dead":false,"Pid":0,"ExitCode":143,"Error":"","StartedAt":"2023-05-03T09:00:59.247569407Z","FinishedAt":"2023-05-03T09:01:03.115883452Z","Health":null},"ID":"8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900","Created":"2022-10-07T05:43:24.764924571Z","Managed":false,"Path":"/usr/bin/tini","Args":["--","/usr/local/bin/jenkins.sh"],"Config":{"Hostname":"8685eaddcd52","Domainname":"","User":"jenkins","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":{"50000/tcp":{},"8080/tcp":{}},"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","LANG=C.UTF-8","JENKINS_HOME=/var/jenkins_home","JENKINS_SLAVE_AGENT_PORT=50000","REF=/usr/share/jenkins/ref","JENKINS_VERSION=2.346.3","JENKINS_UC=https://updates.jenkins.io","JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental","JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals","COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log","JAVA_HOME=/opt/java/openjdk"],"Cmd":null,"Image":"jenkins/jenkins:2.346.3-2-jdk8","Volumes":{"/var/jenkins_home":{}},"WorkingDir":"","Entrypoint":["/usr/bin/tini","--","/usr/local/bin/jenkins.sh"],"OnBuild":null,"Labels":{"org.opencontainers.image.description":"The Jenkins Continuous Integration and Delivery server","org.opencontainers.image.licenses":"MIT","org.opencontainers.image.revision":"4c18c51dfed0575dcc6a9220a6475a71c419dac1","org.opencontainers.image.source":"https://github.com/jenkinsci/docker","org.opencontainers.image.title":"Official Jenkins Docker image","org.opencontainers.image.url":"https://www.jenkins.io/","org.opencontainers.image.vendor":"Jenkins project","org.opencontainers.image.version":"2.346.3"}},"Image":"sha256:0e48d93a1a731b327c9d8ea1af728563c3b40db5af4d409bfaab1a38d0ed0ede","NetworkSettings":{"Bridge":"","SandboxID":"99ec7f9c506b640ceb1bf02137cbed7ae61ca9e58026134c5a24cc926f78e77c","HairpinMode":false,"LinkLocalIPv6Address":"","LinkLocalIPv6PrefixLen":0,"Networks":{"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"d908aba67e9a28304393f876c69d5610c8fcca64cb865805d9d4144fbe45ccb8","EndpointID":"","Gateway":"","IPAddress":"","IPPrefixLen":0,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"","DriverOpts":null,"IPAMOperational":false}},"Service":null,"Ports":null,"SandboxKey":"/var/run/docker/netns/99ec7f9c506b","SecondaryIPAddresses":null,"SecondaryIPv6Addresses":null,"IsAnonymousEndpoint":false,"HasSwarmEndpoint":false},"LogPath":"/var/lib/docker/containers/8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900/8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900-json.log","Name":"/jenkins","Driver":"overlay2","OS":"linux","MountLabel":"","ProcessLabel":"","RestartCount":0,"HasBeenStartedBefore":true,"HasBeenManuallyStopped":false,"MountPoints":{"/var/jenkins_home":{"Source":"/appdata/jenkins","Destination":"/var/jenkins_home","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"/appdata/jenkins","Target":"/var/jenkins_home"},"SkipMountpointCreation":false}},"SecretReferences":null,"ConfigReferences":null,"AppArmorProfile":"","HostnamePath":"/var/lib/docker/containers/8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900/hostname","HostsPath":"/var/lib/docker/containers/8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900/hosts","ShmPath":"","ResolvConfPath":"/var/lib/docker/containers/8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900/resolv.conf","SeccompProfile":"","NoNewPrivileges":false,"LocalLogCacheMeta":{"HaveNotifyEnabled":false}}
修改后:
关键版
"MountPoints": {
"/var/jenkins_home": {
"Source": "/appdata/jenkins",
"Destination": "/var/jenkins_home",
"RW": true,"Name": "",
"Driver": "",
"Type": "bind",
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "/appdata/jenkins",
"Target": "/var/jenkins_home"
},
"SkipMountpointCreation": false
},
"/usr/bin/docker": {
"Source": "/usr/bin/docker",
"Destination": "/usr/bin/docker",
"RW": true,"Name": "",
"Driver": "",
"Type": "bind",
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "/usr/bin/docker",
"Target": "/usr/bin/docker"
},
"SkipMountpointCreation": false
},
"/var/run/docker.sock": {
"Source": "/var/run/docker.sock",
"Destination": "/var/run/docker.sock",
"RW": true,
"Name": "",
"Driver": "",
"Type": "bind",
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock"
},"SkipMountpointCreation": false
}
}
完整版文章来源:https://www.toymoban.com/news/detail-771570.html
{"StreamConfig":{},"State":{"Running":false,"Paused":false,"Restarting":false,"OOMKilled":false,"RemovalInProgress":false,"Dead":false,"Pid":0,"ExitCode":143,"Error":"","StartedAt":"2023-05-03T09:00:59.247569407Z","FinishedAt":"2023-05-03T09:01:03.115883452Z","Health":null},"ID":"8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900","Created":"2022-10-07T05:43:24.764924571Z","Managed":false,"Path":"/usr/bin/tini","Args":["--","/usr/local/bin/jenkins.sh"],"Config":{"Hostname":"8685eaddcd52","Domainname":"","User":"jenkins","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":{"50000/tcp":{},"8080/tcp":{}},"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","LANG=C.UTF-8","JENKINS_HOME=/var/jenkins_home","JENKINS_SLAVE_AGENT_PORT=50000","REF=/usr/share/jenkins/ref","JENKINS_VERSION=2.346.3","JENKINS_UC=https://updates.jenkins.io","JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental","JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals","COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log","JAVA_HOME=/opt/java/openjdk"],"Cmd":null,"Image":"jenkins/jenkins:2.346.3-2-jdk8","Volumes":{"/var/jenkins_home":{}},"WorkingDir":"","Entrypoint":["/usr/bin/tini","--","/usr/local/bin/jenkins.sh"],"OnBuild":null,"Labels":{"org.opencontainers.image.description":"The Jenkins Continuous Integration and Delivery server","org.opencontainers.image.licenses":"MIT","org.opencontainers.image.revision":"4c18c51dfed0575dcc6a9220a6475a71c419dac1","org.opencontainers.image.source":"https://github.com/jenkinsci/docker","org.opencontainers.image.title":"Official Jenkins Docker image","org.opencontainers.image.url":"https://www.jenkins.io/","org.opencontainers.image.vendor":"Jenkins project","org.opencontainers.image.version":"2.346.3"}},"Image":"sha256:0e48d93a1a731b327c9d8ea1af728563c3b40db5af4d409bfaab1a38d0ed0ede","NetworkSettings":{"Bridge":"","SandboxID":"99ec7f9c506b640ceb1bf02137cbed7ae61ca9e58026134c5a24cc926f78e77c","HairpinMode":false,"LinkLocalIPv6Address":"","LinkLocalIPv6PrefixLen":0,"Networks":{"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"d908aba67e9a28304393f876c69d5610c8fcca64cb865805d9d4144fbe45ccb8","EndpointID":"","Gateway":"","IPAddress":"","IPPrefixLen":0,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"","DriverOpts":null,"IPAMOperational":false}},"Service":null,"Ports":null,"SandboxKey":"/var/run/docker/netns/99ec7f9c506b","SecondaryIPAddresses":null,"SecondaryIPv6Addresses":null,"IsAnonymousEndpoint":false,"HasSwarmEndpoint":false},"LogPath":"/var/lib/docker/containers/8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900/8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900-json.log","Name":"/jenkins","Driver":"overlay2","OS":"linux","MountLabel":"","ProcessLabel":"","RestartCount":0,"HasBeenStartedBefore":true,"HasBeenManuallyStopped":false,"MountPoints":{"/var/jenkins_home":{"Source":"/appdata/jenkins","Destination":"/var/jenkins_home","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"/appdata/jenkins","Target":"/var/jenkins_home"},"SkipMountpointCreation":false},"/usr/bin/docker":{"Source":"/usr/bin/docker","Destination":"/usr/bin/docker","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"/usr/bin/docker","Target":"/usr/bin/docker"},"SkipMountpointCreation":false},"/var/run/docker.sock":{"Source":"/var/run/docker.sock","Destination":"/var/run/docker.sock","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"/var/run/docker.sock","Target":"/var/run/docker.sock"},"SkipMountpointCreation":false}},"SecretReferences":null,"ConfigReferences":null,"AppArmorProfile":"","HostnamePath":"/var/lib/docker/containers/8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900/hostname","HostsPath":"/var/lib/docker/containers/8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900/hosts","ShmPath":"","ResolvConfPath":"/var/lib/docker/containers/8685eaddcd52f2f770526975a48a3ee6714eb9a0029cb5841a100ee3c84ae900/resolv.conf","SeccompProfile":"","NoNewPrivileges":false,"LocalLogCacheMeta":{"HaveNotifyEnabled":false}}
实验结果
[root@appserver ~]# docker ps -a |grep jenkins
8685eaddcd52 jenkins/jenkins:2.346.3-2-jdk8 "/usr/bin/tini -- /u…" 6 months ago Up 25 minutes 0.0.0.0:8099->8080/tcp, :::8099->8080/tcp, 0.0.0.0:50099->50000/tcp, :::50099->50000/tcp jenkins
[root@appserver ~]# docker exec -it 8685eaddcd52 /bin/bash
jenkins@8685eaddcd52:/$ ls -al /usr/bin/docker
-rwxr-xr-x. 1 root root 61811904 Oct 4 2021 /usr/bin/docker
jenkins@8685eaddcd52:/$ ls -al /var/run/docker.sock
srw-rw---- 1 root 985 0 May 3 09:13 /var/run/docker.sock
其他方式
Docker 修改容器参数文章来源地址https://www.toymoban.com/news/detail-771570.html
到了这里,关于docker容器修改挂载路径的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!