Docker learning

Centon 8 Install Docker

  1. Uninstall the previous version

    yum remove docker
    Copy the code
  2. Basic Installation Information

    yum install -y yum-utils
    Copy the code
  3. Setting up the Mirror Warehouse

    #Don't default to this on the official website!
    $ sudo yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo # default is foreign
    
    #Replace it with the following
    
    $ sudo yum-config-manager \
        --add-repo \
        https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # Aliyun Mirror
    Copy the code
    1. Image Package Index

      yum makecache fast
      Copy the code

      Yum makecache: error: argument timer: invalid choice: ‘fast’ (choose from ‘timer’)

      Centos8 does not have this parameter, the solution is: remove the fast parameter, it is ok

      yum makecache
      Copy the code
  4. Install the Docker engine

    Yum install docker-ce docker-ce-cli containerd. IO # docker-ceCopy the code

    The following problems may occur during installation

    Last metadata expiration check: 0:01:06 ago on Sat 05 Dec 2020 03:44:27 PM CST. Error: Problem: Package docker-CE-3:19.03.14-3.el7.x86_64 requires Containerd. IO >= 1.2.2-3, but none of the providers can be installed

    • cannot install the best candidate for the job

    • Package ContainerD. io-1.2.10-3.2.el7.x86_64 is filtered out by Modular filtering

    • Package ContainerD. io-1.2.13-3.1.el7.x86_64 is filtered out by Modular filtering

    • Package ContainerD. io-1.2.13-3.2.el7.x86_64 is filtered out by Modular filtering

    • Package ContainerD. io-1.2.2-3.3.el7.x86_64 is filtered out by Modular filtering

    • Package ContainerD. io-1.2.2-3.el7.x86_64 is filtered out by Modular filtering

    • Package ContainerD. io-1.2.4-3.1.el7.x86_64 is filtered out by Modular filtering

    • Package ContainerD. io-1.2.5-3.1.el7.x86_64 is filtered out by Modular filtering

    • Package ContainerD. io-1.2.6-3.3.el7.x86_64 is filtered out by Modular filtering

    • Package ContainerD. io-1.3.7-3.1.el7.x86_64 is filtered out by Modular filtering

    • Package ContainerD. io-1.3.9-3.1.el7.x86_64 is filtered out by modular filtering (try to add ‘–skip-broken’ to skip uninstallable packages or ‘–nobest’ to use not only best candidate packages

    Yum install docker-ce docker-ce cli containerd. IO

    yum update
    
    dnf install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
    
    yum install docker-ce docker-ce-cli containerd.io
    Copy the code

    Notice that there are a couple of y/n decisions here

    All the way y will do

    Don’t stop at Complet!

  5. Start the Docker

    Systemctl start docker # indicates that the system is successfully startedCopy the code
  6. View the Docker version

    docker version
    Copy the code
    Client: Docker engine-community Version: 19.03.14 API Version: 1.40 Go Version: go1.13.15 Git commit: 5eb3275d40 Built: Tue Dec 1 19:20:42 2020 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03.14 API Version: 1.40 (minimum Version 1.12) Go Version: Go1.13.15 Git commit: 5eb3275d40 Built: Tue Dec 1 19:19:17 2020 OS/Arch: Linux/AMd64 Experimental: false containerd: Version: 1.2.6 GitCommit: 894 b81a4b802e4eb2a91d1ce216b8817763c29fb runc: Version: 1.0.0 - rc8 GitCommit: 425 e105d5a03fabd737a126ad93d62a9eeede87f docker - init: Version: 0.18.0 GitCommit: fec3683Copy the code

Run Hello for the first time

docker run hello-world
Copy the code

The middle pile is the signature information

Flow chart of run

Viewing download Image

docker images
Copy the code

Uninstall the Docker

#Unload rely on
yum remove docker-ce docker-ce-cli containerd.io

#Delete the resourceRm -rf /var/lib/docker # The default working path of dockerCopy the code

Ali Cloud image acceleration

Json <<-'EOF' {"registry-mirrors": [" https://uyfgafsw.mirror.aliyuncs.com "]} EOF # write configuration files sudo systemctl daemon - reload # restart service sudo systemctl restart Docker # restart dockerCopy the code

The underlying principle

  1. How does Docker work?

    Docker is a client-server structure of the system, Docker daemon on the host. Access from client through Socket!

    DockerServer receives the instruction from docker-client,

  1. Why is Docker faster than VM?
    1. Docker has fewer layers of abstraction than virtual machines
    2. Docker mainly uses the kernel of host computer, and VM requires Guest OS

So when creating a container, Docker doesn’t need to reload an operating system kernel like a virtual machine, avoiding booting

Docker command

Docker version # display the basic information of docker docker info # system information, the number of images and containers docker command --help # complete informationCopy the code

The mirror command

##### View all mirrorsCopy the code
docker images
Copy the code

explain

REPOSITORY TAG # IMAGE ID # IMAGE ID CREATED # IMAGE creation time SIZE # IMAGE SIZE

--all , -a		Show all images (default hides intermediate images) # display all--digests Show digests --filter , -f Filter output based on conditions provided --format Pretty-print images using a Go template --no-trunc Don't truncate  output --quiet , -q Only show numeric IDs# display id only
Copy the code
Image search
docker search mysql
Copy the code

Docker search --help # search help documentsCopy the code

Docker search --filter=STARS=3000Copy the code

Download mirror
Docker pull mysql # download mysql image, default tag, default latest versionCopy the code
[root@ysl ~]# docker pull mysql Using default tag: latest Pulling from Library /mysql 852e50CD189d: Pull complete #layer Pulling from library/mysql 852e50CD189d: Pull complete #layer Pull complete a43f41a44c48: Pull complete 5cdd802543a3: Pull complete b79b040de953: Pull complete 938c64119969: Pull complete 7689ec51a0d9: Pull complete a880ba7c411f: Pull complete 984f656ec6ca: Pull complete 9f497bce458a: Pull complete b9940f97694b: Pull complete 2f069358dc96: Pull complete Digest: Sha256: # 4 bb2e81a40e9d0d59bd8e3dc2ba5e1f2197696f6de39a91e90798dd27299b093 signature Status: Downloaded newer image for mysql: latest docker. IO/library/mysql: latest# real address

#namely
docker pull mysql
#Is equivalent to
docker pull docker.io/library/mysql:latest

Copy the code
Docker pull mysql: 5.7 #Copy the code

Remove the mirror
#-f deletes all files. The value can be specified by name or id
docker rmi -f 9cfcce23593a
#Delete multiple ids separated by Spaces
docker rmi -f id id id
#Delete allDocker rmi-f $(docker images -aq) # images -aqCopy the code

Container order

With the image to create containers, Linux, download a centos image to test learning

Create a new container and start
Docker run [Optional] image
#Parameters that- name = "name" # vessel name, is used to distinguish the container - run d the background - it USES interactive way, enter the container for content -p designated container port Such as the -p 8080:8080 - p IP: host port: Container port -p Host port: Container port -p Container port -p Randomly specified portCopy the code
Enter exit container
Docker run -it centos /bin/bashCopy the code

Note the host name, programming the centos ID

It’s a container in here. It’s a nesting doll

View running containers
#View the running container
docker ps
#View the container that was running
docker ps -a
#Displays recently created containers. Set the number of containers to display
docker ps -a - n=? 
#Only the container number is displayed
docker ps -aq
Copy the code
[root@ysl ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@ysl ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
054c11f658bb        centos              "/bin/bash"         5 minutes ago       Exited (0) 5 minutes ago                       blissful_ramanujan
c34be0c5f89a        hello-world         "/hello"            3 hours ago         Exited (0) 3 hours ago                         practical_edison
[root@ysl ~]# docker ps -a -n 2
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
054c11f658bb        centos              "/bin/bash"         5 minutes ago       Exited (0) 5 minutes ago                       blissful_ramanujan
c34be0c5f89a        hello-world         "/hello"            3 hours ago         Exited (0) 3 hours ago                         practical_edison
[root@ysl ~]# docker ps -a -n 1
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
054c11f658bb        centos              "/bin/bash"         5 minutes ago       Exited (0) 5 minutes ago                       blissful_ramanujan
[root@ysl ~]# docker ps -aq
054c11f658bb
c34be0c5f89a
[root@ysl ~]# 

Copy the code
Out of the container
#Container stop exit
exit
#The container does not stop exiting. Note that the input method must be in English, but not in Chinese
Ctrl + P + Q
Copy the code
Remove the container
#Deleting a specified container The running container cannot be deleted if rm -f is forcibly deletedDocker RM Container ID#Delete all containers
docker rm -f $(docker ps -aq)
#Delete all containers
docker ps -a -q|xargs docker rm
Copy the code
[root@ysl ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 40e35224b8f8 centos "/bin/bash" 2 minutes ago Up 2 minutes sad_liskov 054c11f658bb centos "/bin/bash" 11 minutes ago Exited (0) 11 minutes ago blissful_ramanujan c34be0c5f89a hello-world "/hello" 3 hours ago Exited (0) 3 hours ago practical_edison [root@ysl ~]# docker rm 054c11f658bb 054c11f658bb [root@ysl ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 40e35224b8f8 centos "/bin/bash" 2 minutes ago Up 2 minutes sad_liskov c34be0c5f89a hello-world "/hello" 3 hours ago Exited (0) 3 hours ago practical_edison [root@ysl ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 40e35224b8f8 centos "/bin/bash" 4 minutes ago Up 4 minutes sad_liskov [root@ysl ~]# docker rm 40e35224b8f8 #  Error response from daemon: You cannot remove a running container 40e35224b8f8e16274f47cdb6d8c96d5dac4ec9774cc8d2acf1a22e15105a953. Stop the container before attempting removal or force remove [root@ysl ~]#Copy the code
Start and stop container operations
Docker start # restart docker stop # stop Docker killCopy the code
[root@ysl ~]# docker run -it centos /bin/bash [root@d0ae0f87520f /]# exit exit [root@ysl ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@ysl ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d0ae0f87520f centos "/bin/bash" About a minute ago Exited (0) 10 seconds ago eloquent_shamir 40e35224b8f8 centos "/bin/bash" 11 minutes ago Exited (0) 3 minutes ago sad_liskov c34be0c5f89a hello-world "/hello" 3 hours ago Exited (0) 3 hours ago practical_edison [root@ysl ~]# docker start c34be0c5f89a c34be0c5f89a [root@ysl ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@ysl ~]# docker start d0AE0F87520f [root@ysl ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d0ae0f87520f centos "/bin/bash" 2 minutes ago Up 2 Seconds eloquent_shamir [root@ysl ~]# docker stop d0ae0f87520f [root@ysl ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@ysl ~]#Copy the code

Other Common Commands

Start and close Docker
Systemctl start docker systemctl stop dockerCopy the code
Background Startup Image
Docker run -d specifies the image name#When the container is started, Docker will immediately stop when it finds that it does not provide services
Copy the code
[root@ysl ~]# docker run -d centos # 831447907dacbce9d81d363cdaf946a4e1ab4e07c3ea41a4a8bebcc39f0e85dc [root@ysl ~]# Docker ps # docker ps # docker ps # docker ps # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@ysl ~]#Copy the code
See the log
Docker logs docker logs -f -t --tail n [id] #Copy the code
Docker logs --help # Fetch the logs of a CONTAINER OPTIONS: --details Show extra details provided to logs -f, --follow Follow log output --since string Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for  42 minutes) --tail string Number of lines to show from the end of the logs (default "all") -t, --timestamps Show timestamps --until string Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)#Run centos inside add a script[root@ysl ~]# docker run -d centos /bin/sh -c "while true; Do echo C. sleep 1; done" a090835bd80a92c306552ad1e3f8878d30218a3930363a02c7d3dda9fd58dc11 [root@ysl ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES A090835bD80A centos "/bin/sh -c 'while t..." 37 seconds ago Up 36 seconds mystifying_knuth a1a1ec80a208 centos "/bin/bash" 4 minutes ago Up 4 minutes charming_ride [root@ysl ~]# docker logs -f-t --tail 10 a090835bd80a # 2020-12-06T11:06:27.430555293z 2020-12-06T11:06:28.432140658Z 2020-12-06T11:06:29.433564252Z 2020-12-06T11:06:30.435042497z 2020-12-06T11:06:30.435042497z 2020-12-06T11:06:31.436566532Z 2020-12-06T11:06:32.438258329Z 2020-12-06T11:06:33.439975118z 2020-12-06T11:06:33.439975118z 2020-12-06T11:06:31.436566532z 2020-12-06T11:06:34.441652220Z 2020-12-06T11:06:35.443275405ZCopy the code
View complete information about the running container
Docker inspect specifies the container nameCopy the code
[root@ysl ~]# docker inspect a090835bd80a
[
    {
		#Complete id    
        "Id": "a090835bd80a92c306552ad1e3f8878d30218a3930363a02c7d3dda9fd58dc11",
        #创建时间
        "Created": "2020-12-06T11:05:28.871924563Z",
       #脚本位置
       "Path": "/bin/sh",
        #运行的脚本
        "Args": [
            "-c",
            "while true;do echo 加油;sleep 1;done"
        ],
        "State": {
            "Status": "running", #状态,正在运行
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 102361, #父进程id
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2020-12-06T11:05:29.359496168Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        #来源镜像
        "Image": "sha256:0d120b6ccaa8c5e149176798b3501d4dd1885f961922497cd0abef155c869566",
        "ResolvConfPath": "/var/lib/docker/containers/a090835bd80a92c306552ad1e3f8878d30218a3930363a02c7d3dda9fd58dc11/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/a090835bd80a92c306552ad1e3f8878d30218a3930363a02c7d3dda9fd58dc11/hostname",
        "HostsPath": "/var/lib/docker/containers/a090835bd80a92c306552ad1e3f8878d30218a3930363a02c7d3dda9fd58dc11/hosts",
        "LogPath": "/var/lib/docker/containers/a090835bd80a92c306552ad1e3f8878d30218a3930363a02c7d3dda9fd58dc11/a090835bd80a92c306552ad1e3f8878d30218a3930363a02c7d3dda9fd58dc11-json.log",
        "Name": "/mystifying_knuth",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        #主机配置
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Capabilities": null,
            "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"
            ]
        },
        #其他配置
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/e23f8f5784064d4b3702358bf17453096310b90f0dd43c180fafb30109672e6e-init/diff:/var/lib/docker/overlay2/ebace8a6bc46f06628921d249a99eb8ec3b12fdb47a2c40e66989690c97969d1/diff",
                "MergedDir": "/var/lib/docker/overlay2/e23f8f5784064d4b3702358bf17453096310b90f0dd43c180fafb30109672e6e/merged",
                "UpperDir": "/var/lib/docker/overlay2/e23f8f5784064d4b3702358bf17453096310b90f0dd43c180fafb30109672e6e/diff",
                "WorkDir": "/var/lib/docker/overlay2/e23f8f5784064d4b3702358bf17453096310b90f0dd43c180fafb30109672e6e/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],#挂载
        #基本配置
        "Config": {
            "Hostname": "a090835bd80a",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ], #基本环境变量
            #基本命令
            "Cmd": [
                "/bin/sh",
                "-c",
                "while true;do echo 加油;sleep 1;done"
            ],
            "Image": "centos",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20200809",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS"
            }
        },
        #网卡,比如现在用的是桥接的网卡
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "a7b521474bb5603d76d12275115a14d85664a860b463f438859711ac71a0b032",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/a7b521474bb5",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "a8129a09e534148c7339fd04039ead2704468dec190059ad58c4ea376077e41c",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:03",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "6b3878e096dcd5ddd4238ff53e18ff7dc6e5056d7328a1dce1b980b4aedff9e4",
                    "EndpointID": "a8129a09e534148c7339fd04039ead2704468dec190059ad58c4ea376077e41c",
                    "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
                }
            }
        }
    }
]

Copy the code
Enter the running container
Docker attach docker attach docker attach docker attach docker attach docker attachCopy the code
#test
#Method 1
[root@ysl ~]# docker exec -it a1a1ec80a208 /bin/bash
[root@a1a1ec80a208 /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@a1a1ec80a208 /]# ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 11:01 pts/0    00:00:00 /bin/bash
root          15       0  1 11:23 pts/1    00:00:00 /bin/bash
root          29      15  0 11:24 pts/1    00:00:00 ps -ef
[root@a1a1ec80a208 /]# exit
exit
[root@ysl ~]# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
a1a1ec80a208        centos              "/bin/bash"         25 minutes ago      Up 58 seconds                           charming_ride
#Method 2
[root@ysl ~]# docker attach a1a1ec80a208
[root@a1a1ec80a208 /]# docker ps 
bash: docker: command not found
[root@a1a1ec80a208 /]# ps -ef 
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 11:01 pts/0    00:00:00 /bin/bash
root          31       1  0 11:24 pts/0    00:00:00 ps -ef
[root@a1a1ec80a208 /]# exit
exit
[root@ysl ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

#The difference between
# docker exec After entering the container, open a new terminal and you can operate in it. After exiting the container, the container will work properly
#Docker Attach enters the terminal where the container is executing and does not start a new process inexitAfter exiting, the container closes

Copy the code
Copies files from the container to the host
Docker cp Container ID: full path of container files to be copied to the hostCopy the code
[root@ysl ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a1a1ec80a208 centos "/bin/bash" 2 hours ago Up 2 hours charming_ride [root@ysl ~]# docker attach a1a1ec80a208 [root@a1a1ec80a208 /]# ls bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var [root@a1a1ec80a208 /]# cd home/ [root@a1a1ec80a208  home]# ls [root@a1a1ec80a208 home]# touch test.java [root@a1a1ec80a208 home]# ls test.java [root@a1a1ec80a208 home]# exit exit [root@ysl ~]# cd /home/ [root@ysl home]# ls mysql#The container file is copied to the host
[root@ysl home]# docker cp a1a1ec80a208:/home/test.java /home
[root@ysl home]# ls
mysql  test.java 
Copy the code
Viewing Memory Usage
docker stats
Copy the code
CONTAINER ID NAME CPU % MEM USAGE/LIMIT MEM % NET I/O BLOCK I/O PIDS a1a1EC80a208 charming_ride 0.00% 1.102MiB / 1.705GiB 0.06% 1.87kB / 0B 0B / 0B 1Copy the code

Docker mirror