docker学习笔记-基础理论、环境搭建、常用命令(一)

2019-11-28  本文已影响0人  Sandra_liu

1、docker作用

a、搭建测试环境 再也不用抢分支了
b、搭建测试执行环境
c、搭建各类服务

2、docker和虚拟机的区别

docker无虚拟化内核,使用宿主机的内核

3、docker的关键技术

namespace:linux命名空间,隔离网络
Cgroups:限制和隔离进程资源(cpu、内存)
联合文件系统:隔离文件视图

4、docker安装

参考官方文档:https://docs.docker.com/install/linux/docker-ce/centos/
下面是 centos 上安装 docker 的命令示例过程

安装依赖

$ yum install -y yum-utils device-mapper-persistent-data lvm2

添加 docker 的yum镜像源,如果在国内,添加阿里云的镜像源

安装 docker 官方的镜像源

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

如果在国内,安装阿里云的镜像

$ yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

安装指定版本的 docker 并且启动服务

安装 docker

$ yum install -y docker-ce

安装指定版本号的 docker,以下是 k8s 官方推荐的 docker 版本号 (此时,k8s 的版本号在 v1.16)

$ yum install -y docker-ce-18.06.2.ce
$ systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

$ systemctl start docker

docker 安装成功后,可以使用以下命令查看版本号

$ docker --version
Docker version 18.06.2-ce, build 6d37f41

查看更详细的版本号信息

$ docker version

查看docker的详细配置信息

$ docker info

5、镜像管理命令(举个🌰:jenkins)

docker镜像的下载地址:https://hub.docker.com/

docker pull jenkins/jenkins:lts
docker push jenkins/jenkins:1.0 
[root@VM_0_4_centos ~]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
docker.io/jenkins/jenkins   1.0                 22b8b9a84dbe        9 days ago          568 MB
    - REPOSITORY:仓库    docker.io/jenkins/jenkins:镜像存放地址/镜像名称
    - TAG:镜像版本号  不加版本号默认会加最新的版本号 latest
    - IMAGE ID:镜像ID  全球唯一
    - CREATED:镜像制作时间
    - SIZE:镜像所占的磁盘时间
[root@VM_0_4_centos ~]# docker tag  docker.io/jenkins/jenkins:lts  docker.io/jenkins/jenkins:1.0

[root@VM_0_4_centos ~]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
docker.io/jenkins/jenkins   1.0                 22b8b9a84dbe        9 days ago          568 MB
docker.io/jenkins/jenkins   lts                 22b8b9a84dbe        9 days ago          568 MB
[root@VM_0_4_centos ~]# docker save docker.io/jenkins/jenkins > jenkins.tar
[root@VM_0_4_centos ~]# ll
总用量 565880
-rw-r--r-- 1 root root 579456512 11月 30 10:24 jenkins.tar
[root@VM_0_4_centos ~]# docker load < jenkins.tar 
Loaded image: docker.io/jenkins/jenkins:lts
[root@VM_0_4_centos ~]# docker tag  docker.io/jenkins/jenkins:lts  sandrajenkins
[root@VM_0_4_centos ~]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
sandrajenkins               latest              22b8b9a84dbe        9 days ago          568 MB
docker.io/jenkins/jenkins   1.0                 22b8b9a84dbe        9 days ago          568 MB
docker.io/jenkins/jenkins   lts                 22b8b9a84dbe        9 days ago          568 MB
[root@VM_0_4_centos ~]# docker rmi 22b8b9a84dbe
Error response from daemon: conflict: unable to delete 22b8b9a84dbe (must be forced) - image is referenced in multiple repositories
[root@VM_0_4_centos ~]# docker rmi docker.io/jenkins/jenkins:1.0
Untagged: docker.io/jenkins/jenkins:1.0

6、容器的管理命令

[root@VM_0_4_centos jenkins]# docker run --name  sandrajenkins -d -p 8080:8080 -p 50000:50000   sandrajenkins
9a0fa36a1857b75d4bdfe7e28f986d055b7b63c4a676ae0820e9eeb772dd6e71
[root@VM_0_4_centos jenkins]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                              NAMES
9a0fa36a1857        sandrajenkins       "/sbin/tini -- /us..."   7 minutes ago       Up 7 minutes        0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   sandrajenkins
CONTAINER ID:容器的唯一标识
IMAGE :容器是通过哪个镜像启动的
COMMAND:启动名称
CREATED :容器创建时间
STATUS :当前状态
PORTS :端口号
NAMES:容器的名称

[root@VM_0_4_centos jenkins]# docker ps -s
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                              NAMES               SIZE
9a0fa36a1857        sandrajenkins       "/sbin/tini -- /us..."   10 minutes ago      Up 10 minutes       0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   sandrajenkins       2.42 MB (virtual 570 MB)
SIZE:容器所占的磁盘空间  2.42 MB (virtual 570 MB-> 镜像大小)

[root@VM_0_4_centos jenkins]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                              NAMES
9a0fa36a1857        sandrajenkins       "/sbin/tini -- /us..."   13 minutes ago      Up 13 minutes       0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   sandrajenkins

[root@VM_0_4_centos jenkins]# docker stop 9a0fa36a1857
9a0fa36a1857

[root@VM_0_4_centos jenkins]# docker stop sandrajenkins
sandrajenkins
[root@VM_0_4_centos jenkins]# docker kill 9a0fa36a1857
9a0fa36a1857
[root@VM_0_4_centos jenkins]# docker rm -f sandrajenkins
sandrajenkins
[root@VM_0_4_centos jenkins]# docker restart 9a0fa36a1857
9a0fa36a1857

[root@VM_0_4_centos jenkins]# docker restart sandrajenkins
sandrajenkins

7、查询信息相关命令

[root@VM_0_4_centos jenkins]# docker logs -f sandrajenkins 
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2019-11-30 04:01:28.690+0000 [id=1] INFO    org.eclipse.jetty.util.log.Log#initialized: Logging initialized @618ms to org.eclipse.jetty.util.log.JavaUtilLog
2019-11-30 04:01:28.875+0000 [id=1] INFO    winstone.Logger#logInternal: Beginning extraction from war file
2019-11-30 04:01:30.285+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2019-11-30 04:01:30.380+0000 [id=1] INFO    org.eclipse.jetty.server.Server#doStart: jetty-9.4.z-SNAPSHOT; built: 2019-05-02T00:04:53.875Z; git: e1bc35120a6617ee3df052294e433f3a25ce7097; jvm 1.8.0_232-b09
2019-11-30 04:01:30.716+0000 [id=1] INFO    o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2019-11-30 04:01:30.786+0000 [id=1] INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2019-11-30 04:01:30.786+0000 [id=1] INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2019-11-30 04:01:30.792+0000 [id=1] INFO    o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 600000ms
Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2019-11-30 04:01:31.471+0000 [id=1] INFO    o.e.j.s.handler.ContextHandler#doStart: Started w.@53499d85{Jenkins v2.190.3,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2019-11-30 04:01:31.514+0000 [id=1] INFO    o.e.j.server.AbstractConnector#doStart: Started ServerConnector@302c971f{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2019-11-30 04:01:31.514+0000 [id=1] INFO    org.eclipse.jetty.server.Server#doStart: Started @3443ms
2019-11-30 04:01:31.516+0000 [id=20]    INFO    winstone.Logger#logInternal: Winstone Servlet Engine v4.0 running: controlPort=disabled
2019-11-30 04:01:32.974+0000 [id=27]    INFO    jenkins.InitReactorRunner$1#onAttained: Started initialization
2019-11-30 04:01:33.043+0000 [id=25]    INFO    jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2019-11-30 04:01:34.813+0000 [id=26]    INFO    jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2019-11-30 04:01:34.824+0000 [id=26]    INFO    jenkins.InitReactorRunner$1#onAttained: Started all plugins
2019-11-30 04:01:34.871+0000 [id=26]    INFO    jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2019-11-30 04:01:35.878+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2019-11-30 04:01:35.937+0000 [id=41]    INFO    hudson.model.AsyncPeriodicWork$1#run: Started Download metadata
2019-11-30 04:01:35.978+0000 [id=41]    INFO    hudson.util.Retrier#start: Attempt #1 to do the action check updates server
2019-11-30 04:01:37.199+0000 [id=25]    INFO    o.s.c.s.AbstractApplicationContext#prepareRefresh: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@16869b76: display name [Root WebApplicationContext]; startup date [Sat Nov 30 04:01:37 UTC 2019]; root of context hierarchy
2019-11-30 04:01:37.199+0000 [id=25]    INFO    o.s.c.s.AbstractApplicationContext#obtainFreshBeanFactory: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@16869b76]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1ce688fd
2019-11-30 04:01:37.215+0000 [id=25]    INFO    o.s.b.f.s.DefaultListableBeanFactory#preInstantiateSingletons: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1ce688fd: defining beans [authenticationManager]; root of factory hierarchy
2019-11-30 04:01:37.452+0000 [id=25]    INFO    o.s.c.s.AbstractApplicationContext#prepareRefresh: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@512cef0f: display name [Root WebApplicationContext]; startup date [Sat Nov 30 04:01:37 UTC 2019]; root of context hierarchy
2019-11-30 04:01:37.453+0000 [id=25]    INFO    o.s.c.s.AbstractApplicationContext#obtainFreshBeanFactory: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@512cef0f]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1b6cd3c6
2019-11-30 04:01:37.453+0000 [id=25]    INFO    o.s.b.f.s.DefaultListableBeanFactory#preInstantiateSingletons: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1b6cd3c6: defining beans [filter,legacy]; root of factory hierarchy
2019-11-30 04:01:37.825+0000 [id=25]    INFO    jenkins.install.SetupWizard#init: 
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
a10041557c8a40e3bf41f44988799d43
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
[root@VM_0_4_centos jenkins]# docker info
Containers: 1
 Running: 1
 Paused: 0
 Stopped: 0
Images: 3
Server Version: 1.13.1
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: journald
Cgroup Driver: systemd
Plugins: 
 Volume: local
 Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: docker-runc runc
Default Runtime: docker-runc
Init Binary: /usr/libexec/docker/docker-init-current
containerd version:  (expected: aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1)
runc version: 9c3c5f853ebf0ffac0d087e94daef462133b69c7 (expected: 9df8b306d01f59d3a8029be411de015b7304dd8f)
init version: fec3683b971d9c3ef73f284f176672c44b448662 (expected: 949e6facb77383876aeff8a6944dde66b3089574)
Security Options:
 seccomp
  WARNING: You're not using the default seccomp profile
  Profile: /etc/docker/seccomp.json
Kernel Version: 3.10.0-957.21.3.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 3
CPUs: 2
Total Memory: 3.701 GiB
Name: VM_0_4_centos
ID: X5DL:YS5M:QDPL:H665:FPT7:PAOU:N7ZK:RR25:IHH4:3THZ:2S52:MXS2
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Registries: docker.io (secure)
[root@VM_0_4_centos jenkins]# docker inspect sandrajenkins
[
    {
        "Id": "6181f0aab75e39107e6e1e35093b265bb22141966d5dac795255a1c8e5218b1b",
        "Created": "2019-11-30T04:01:27.718420678Z",
        "Path": "/sbin/tini",
        "Args": [
            "--",
            "/usr/local/bin/jenkins.sh"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 30012,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2019-11-30T04:01:28.042010247Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:22b8b9a84dbe855962512a090bd80087584626b645f77e0cfd69398f10ad6eda",
        "ResolvConfPath": "/var/lib/docker/containers/6181f0aab75e39107e6e1e35093b265bb22141966d5dac795255a1c8e5218b1b/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/6181f0aab75e39107e6e1e35093b265bb22141966d5dac795255a1c8e5218b1b/hostname",
        "HostsPath": "/var/lib/docker/containers/6181f0aab75e39107e6e1e35093b265bb22141966d5dac795255a1c8e5218b1b/hosts",
        "LogPath": "",
        "Name": "/sandrajenkins",
        "RestartCount": 0,
        "Driver": "overlay2",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "journald",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "50000/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "50000"
                    }
                ],
                "8080/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "8080"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "docker-runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Name": "overlay2",
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/4915f385b4296250f062e6fc4c8f5d810481d42d73ceedbec12a62ec5a0e6ba3-init/diff:/var/lib/docker/overlay2/24b281d90ad227bea57249fdf1825777f91172c4e898c8fa97c42390555b21de/diff:/var/lib/docker/overlay2/b543fabb295340447dd4c8e7cd5eed7ec94206f612cb8885082f700089f91464/diff:/var/lib/docker/overlay2/26c4a625a359fb0d7ee8767dd818eb9245865f275ff273f3324d8ecccd014951/diff:/var/lib/docker/overlay2/0b9600575fea72430e46e695d2a322b0c386eae29c6f982d6b19a8c861ceb570/diff:/var/lib/docker/overlay2/dad8df63591123025fa6f4c45b8a554f5424c6a7668d5266f47b37de9221682a/diff:/var/lib/docker/overlay2/88b5275e82a7daacfc89ad0648737fab235f3cd0d65669c11ee610901c8857ef/diff:/var/lib/docker/overlay2/960eafffcafbd912a2f1b7def238b8c48e1de914c65ea1ad9900e798e506b77b/diff:/var/lib/docker/overlay2/3bfb23cbe887cadbe4f899f88eeb453c7a94bea6f7edb7d926c2e16d3b41a359/diff:/var/lib/docker/overlay2/ed85098f0c828e26e4a45eb762c9c3ec408d70e608cfaf96f5308dbccd35f6b2/diff:/var/lib/docker/overlay2/81d46f1b7cec18bd1fd17308ee6c5a5fb390f0e14211b23c6136ff89a59d4113/diff:/var/lib/docker/overlay2/3792b5e076cb2cd3fbe82e08235e013b89be08f5fe0057de8ce87422cbaeb802/diff:/var/lib/docker/overlay2/a178f65f381fa9436a1746d478a31f9d0e48fb929d5246e02c46d23b5de00336/diff:/var/lib/docker/overlay2/40d54e01a114fc28544c627829e52de1e42cd1af0ed452293dce133703dc6726/diff:/var/lib/docker/overlay2/6462b53ff17e6db9ba16337fc3ff51ba0007388a42d2000e497420cf7948af1b/diff:/var/lib/docker/overlay2/07694669566b1224fa9016dcf5a0c8b1ac48f082cf81c97ccd0dbb8051d9d777/diff:/var/lib/docker/overlay2/9190d964377768e482b100aa710e540a7c1b6c14ebc912b31db43d726b453dcc/diff:/var/lib/docker/overlay2/d12b3fb262dff96089f6b15a5678493f006ac7f3acc06cf4e1424d1429a9f1d2/diff:/var/lib/docker/overlay2/5ff3d3f513bb2ae2cef660ee426d62ac984b1a7b79d0a7543c46f8d7a4800e8d/diff",
                "MergedDir": "/var/lib/docker/overlay2/4915f385b4296250f062e6fc4c8f5d810481d42d73ceedbec12a62ec5a0e6ba3/merged",
                "UpperDir": "/var/lib/docker/overlay2/4915f385b4296250f062e6fc4c8f5d810481d42d73ceedbec12a62ec5a0e6ba3/diff",
                "WorkDir": "/var/lib/docker/overlay2/4915f385b4296250f062e6fc4c8f5d810481d42d73ceedbec12a62ec5a0e6ba3/work"
            }
        },
        "Mounts": [
            {
                "Type": "volume",
                "Name": "e98649401bdba44a16c1075ab876433962afa8502e40a16f0c9e11d7c7576d01",
                "Source": "/var/lib/docker/volumes/e98649401bdba44a16c1075ab876433962afa8502e40a16f0c9e11d7c7576d01/_data",
                "Destination": "/var/jenkins_home",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "6181f0aab75e",
            "Domainname": "",
            "User": "jenkins",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "50000/tcp": {},
                "8080/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "LANG=C.UTF-8",
                "JAVA_HOME=/usr/local/openjdk-8",
                "JAVA_VERSION=8u232",
                "JAVA_BASE_URL=https://github.com/AdoptOpenJDK/openjdk8-upstream-binaries/releases/download/jdk8u232-b09/OpenJDK8U-jdk_",
                "JAVA_URL_VERSION=8u232b09",
                "JENKINS_HOME=/var/jenkins_home",
                "JENKINS_SLAVE_AGENT_PORT=50000",
                "REF=/usr/share/jenkins/ref",
                "JENKINS_VERSION=2.190.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"
            ],
            "Cmd": null,
            "Image": "sandrajenkins",
            "Volumes": {
                "/var/jenkins_home": {}
            },
            "WorkingDir": "",
            "Entrypoint": [
                "/sbin/tini",
                "--",
                "/usr/local/bin/jenkins.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "8920f8d25472111fdb7b2f4d7d482ee06bc06075b8a48afc86fce201d4b717a4",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "50000/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "50000"
                    }
                ],
                "8080/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "8080"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/8920f8d25472",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "50743c3b65849410316f64bf7584b0a267056bada59c66d6e663b24fe2670ccd",
            "Gateway": "172.18.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.18.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:12:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "4852b86324ccb7d865d991bae4480fc9509e909e063c782efbc279ab0cc23781",
                    "EndpointID": "50743c3b65849410316f64bf7584b0a267056bada59c66d6e663b24fe2670ccd",
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:02"
                }
            }
        }
    }
]


7、与docker容器的交互命令

[root@VM_0_4_centos jenkins]# docker  exec  -it sandrajenkins bash
jenkins@6181f0aab75e:/$ ls
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

[root@VM_0_4_centos jenkins_home]# docker cp start.sh sandrajenkins:/var/jenkins_home
[root@VM_0_4_centos ~]# docker exec sandrajenkins  echo "hi"
hi
[root@VM_0_4_centos ~]# docker exec sandrajenkins  ping www.baidu.com
PING www.a.shifen.com (180.101.49.12) 56(84) bytes of data.
64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=1 ttl=47 time=9.30 ms
64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=2 ttl=47 time=9.28 ms

踩坑1:docker挂了怎么解决?

image.png
踩坑2: docker容器删不掉怎么办?
参考:https://cloud.tencent.com/developer/article/1386135

环境搭建部分也可参考:https://juejin.im/post/5dd72b16e51d45351409073d

上一篇下一篇

猜你喜欢

热点阅读