容器启动后增加挂载
背景
jenkins容器启动后,想要执行docker相关命令,这里需要借助宿主机上的,但是容器已经启动,并建立了相关Jenkins项目,不想在重新运行一个容器弄了
参考这篇博客文章
https://blog.csdn.net/qq_39198749/article/details/127731024
config.v2.json
{
"StreamConfig": {},
"State": {
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"RemovalInProgress": false,
"Dead": false,
"Pid": 24589,
"ExitCode": 0,
"Error": "",
"StartedAt": "2023-01-06T03:32:47.789434599Z",
"FinishedAt": "2023-01-06T03:30:39.014800734Z",
"Health": null
},
"ID": "32ed304b9681e2a6e762929c7da7f0e39a792567268292614e5478e15e250290",
"Created": "2023-01-05T07:58:27.140357979Z",
"Managed": false,
"Path": "/usr/bin/tini",
"Args": ["--", "/usr/local/bin/jenkins.sh"],
"Config": {
"Hostname": "32ed304b9681",
"Domainname": "",
"User": "jenkins",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"50000/tcp": {},
"8080/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": ["JAVA_OPTS=-Duser.timezone=Asia/Shanghai", "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.385", "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",
"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": "88b71cf70c104d6822953b99212114918ed44303",
"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.385"
}
},
"Image": "sha256:82146e9f89683bb5b825dc0c5ba078a4dbb41e703ebfa5be75dd34e617c03c16",
"NetworkSettings": {
"Bridge": "",
"SandboxID": "faf2c8451a64b6ece4f541a14a2ad0632f2aa1c44d50471ac105abb52bf7696b",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "bb106ed190cad15947ec09b5e72be1588b924bfb78fe23d4c5bf014795044ec2",
"EndpointID": "90ab8140e9814cd5c1c9a25222e670b126e52348a704ae1f585ed89f4f5845b8",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:03",
"DriverOpts": null,
"IPAMOperational": false
}
},
"Service": null,
"Ports": {
"50000/tcp": [{
"HostIp": "0.0.0.0",
"HostPort": "50000"
}, {
"HostIp": "::",
"HostPort": "50000"
}],
"8080/tcp": [{
"HostIp": "0.0.0.0",
"HostPort": "8888"
}, {
"HostIp": "::",
"HostPort": "8888"
}]
},
"SandboxKey": "/var/run/docker/netns/faf2c8451a64",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"IsAnonymousEndpoint": false,
"HasSwarmEndpoint": false
},
"LogPath": "/var/lib/docker/containers/32ed304b9681e2a6e762929c7da7f0e39a792567268292614e5478e15e250290/32ed304b9681e2a6e762929c7da7f0e39a792567268292614e5478e15e250290-json.log",
"Name": "/myjenkins",
"Driver": "overlay2",
"OS": "linux",
"MountLabel": "",
"ProcessLabel": "",
"RestartCount": 0,
"HasBeenStartedBefore": true,
"HasBeenManuallyStopped": false,
"MountPoints": {
"/var/jenkins_home": {
"Source": "/opt/jenkins",
"Destination": "/var/jenkins_home",
"RW": true,
"Name": "",
"Driver": "",
"Type": "bind",
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "/opt/jenkins/",
"Target": "/var/jenkins_home"
},
"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
},
"/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
}
},
"SecretReferences": null,
"ConfigReferences": null,
"AppArmorProfile": "",
"HostnamePath": "/var/lib/docker/containers/32ed304b9681e2a6e762929c7da7f0e39a792567268292614e5478e15e250290/hostname",
"HostsPath": "/var/lib/docker/containers/32ed304b9681e2a6e762929c7da7f0e39a792567268292614e5478e15e250290/hosts",
"ShmPath": "",
"ResolvConfPath": "/var/lib/docker/containers/32ed304b9681e2a6e762929c7da7f0e39a792567268292614e5478e15e250290/resolv.conf",
"SeccompProfile": "",
"NoNewPrivileges": false,
"LocalLogCacheMeta": {
"HaveNotifyEnabled": false
}
}
hostconfig.json
{
"Binds": ["/opt/jenkins/:/var/jenkins_home","/var/run/docker.sock:/var/run/docker.sock","/usr/bin/docker:/usr/bin/docker"],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"50000/tcp": [{
"HostIp": "",
"HostPort": "50000"
}],
"8080/tcp": [{
"HostIp": "",
"HostPort": "8888"
}]
},
"RestartPolicy": {
"Name": "no",
"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": true,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": ["label=disable"],
"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": null,
"ReadonlyPaths": null
}
本文来自博客园,作者:弩哥++,转载请注明原文链接:https://www.cnblogs.com/bangbangzoutianya/p/17102322.html