一、docker的基础命令
1.docker的帮助命令
//命令 docker --help [root@localhost ~]# docker --help Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/root/.docker") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") --tlskey string Path to TLS key file (default "/root/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: config Manage Docker configs container Manage containers image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker trust Manage trust on Docker images volume Manage volumes
2.启动、关闭、重启docker
//命令 systemctl start docker(启动docker) [root@localhost ~]# systemctl start docker //命令 systemctl stop docker(关闭docker) [root@localhost ~]# systemctl stop docker //命令 systemctl restart docker(重启docker) [root@localhost ~]# systemctl restart docker //命令 systemctl enable docker(设置docker随服务启动而自启动) [root@localhost ~]# systemctl enable docker Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
3.查看
//命令 docker version //查看docker的版本号 [root@localhost ~]# docker version Client: Version: 18.06.3-ce API version: 1.38 Go version: go1.10.3 Git commit: d7080c1 Built: Wed Feb 20 02:26:51 2019 OS/Arch: linux/amd64 Experimental: false Server: Engine: Version: 18.06.3-ce API version: 1.38 (minimum version 1.12) Go version: go1.10.3 Git commit: d7080c1 Built: Wed Feb 20 02:28:17 2019 OS/Arch: linux/amd64 Experimental: false //命令 docker info //更详细的查看docker的运行信息,镜像数和容器数都能看到 [root@localhost ~]# docker info Containers: 2 Running: 0 Paused: 0 Stopped: 2 Images: 2 Server Version: 18.06.3-ce Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e runc version: a592beb5bc4c4092b1b1bac971afed27687340c5 init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 3.10.0-1160.80.1.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 1.786GiB Name: localhost.localdomain ID: OCD3:Y4KG:A4VS:WBS6:IK2G:DFKX:5CBX:IZWD:TPEV:ZBR5:GXOS:4JKL Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false
二、docker的镜像命令
1.查看镜像
//命令 docker images(查看服务器已有的镜像) [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest feb5d9fea6a5 14 months ago 13.3kB centos latest 5d0da3dc9764 14 months ago 231MB
2.搜索镜像
//命令 docker search 镜像名(搜索镜像) [root@localhost ~]# docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation… 13510 [OK] mariadb MariaDB Server is a high performing open sou… 5156 [OK] phpmyadmin phpMyAdmin - A web interface for MySQL and M… 696 [OK] percona Percona Server is a fork of the MySQL relati… 594 [OK] bitnami/mysql Bitnami MySQL Docker Image 79 [OK] databack/mysql-backup Back up mysql databases to... anywhere! 74 linuxserver/mysql-workbench 45 ubuntu/mysql MySQL open source fast, stable, multi-thread… 38 linuxserver/mysql A Mysql container, brought to you by LinuxSe… 38 circleci/mysql MySQL is a widely used, open-source relation… 28 google/mysql MySQL server for Google Compute Engine 22 [OK] rapidfort/mysql RapidFort optimized, hardened image for MySQL 13 bitnami/mysqld-exporter 4 ibmcom/mysql-s390x Docker image for mysql-s390x 2 newrelic/mysql-plugin New Relic Plugin for monitoring MySQL databa… 1 [OK] vitess/mysqlctld vitess/mysqlctld 1 [OK] hashicorp/mysql-portworx-demo 0 rapidfort/mysql-official RapidFort optimized, hardened image for MySQ… 0 docksal/mysql MySQL service images for Docksal - https://d… 0 mirantis/mysql 0 rapidfort/mysql8-ib RapidFort optimized, hardened image for MySQ… 0 cimg/mysql 0 drud/mysql 0 silintl/mysql-backup-restore Simple docker image to perform mysql backups… 0 [OK] corpusops/mysql https://github.com/corpusops/docker-images/ 0 //搜索stars>9000的mysql镜像 [root@localhost ~]# docker search --filter=stars=9000 mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation… 13510 [OK]
3.下载镜像
注意:我们下载的镜像必须是在仓库中能查找到的!!!可以先登录仓库网址查询要下载的镜像及版本。docker仓库官网:https://hub.docker.com/
比如进docker仓库查询一下mysql的镜像及版本:
拉取镜像:
命令:docker pull 镜像名(默认是最新版的)
docker pull 镜像名:tag(拉取指定版本的镜像)
//从仓库拉取mysql镜像 [root@localhost ~]# docker pull mysql:latest latest: Pulling from library/mysql 0bb5c0c24818: Pull complete cbb3106fbb5a: Pull complete 550536ae1d5e: Pull complete 33f98928796e: Pull complete a341087cff11: Pull complete 0e26ac5b33f6: Pull complete c883b83a7112: Pull complete 873af5c876c6: Pull complete 8fe8ebd061d5: Pull complete 7ac2553cf6b4: Pull complete ad655e218e12: Pull complete Digest: sha256:96439dd0d8d085cd90c8001be2c9dde07b8a68b472bd20efcbe3df78cff66492 Status: Downloaded newer image for mysql:latest
4.运行镜像并生成容器
//命令 docker run 镜像名:tag /bin/bash //-it表示以交互式运行 [root@localhost ~]# docker run -it mysql:latest /bin/bash bash-4.4# //使用Ctrl+P+Q退出容器,用docker ps查看刚才运行的容器 bash-4.4# [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 115c9b4f1e0e mysql:latest "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 3306/tcp, 33060/tcp sharp_easley
5.删除镜像
//使用docker images查看已有的镜像 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql latest 3842e9cdffd2 8 days ago 538MB hello-world latest feb5d9fea6a5 14 months ago 13.3kB centos latest 5d0da3dc9764 14 months ago 231MB //命令 docker rmi -f 镜像id(删除某一个镜像,删除多个的话镜像id中间用空格) //删除mysql镜像 [root@localhost ~]# docker rmi -f 3842e9cdffd2 Untagged: mysql:latest Untagged: mysql@sha256:96439dd0d8d085cd90c8001be2c9dde07b8a68b472bd20efcbe3df78cff66492 Deleted: sha256:3842e9cdffd239649671beaec03b363b52f7b050fbb4a8869c052438408d6d2e Deleted: sha256:1f42c1dd3cbbd4976bb03a3e9cda08a64f92c4b35c85406dd61fc675c06fea06 Deleted: sha256:615793330ac611559cd6f0a464f0159eb05ad3876198859c92daf53cb4c57ea0 Deleted: sha256:2d47d08d92e7cee9b5a2a163c37440e9bcf29574c7d603a04254a6c8f6fd2bbb Deleted: sha256:8b7fff5815c437619ff2e5406208d21648a27812d480bcc342a0e32020003ef5 Deleted: sha256:08a8548130ba2c821ff7389faf3a4d60abbd3a6e7b20060231be0fbd2bb16136 Deleted: sha256:86aabdd0cece68ff3ee220072a3b85142e25cb5c18b628d22f4657bae56ccb11 Deleted: sha256:e09dc4db3864b796c659b92bae0babfbf09dfa3f70163dc7cd677fabf5e94ef2 Deleted: sha256:b6d2c75cfbe18df23ef09649426dcb28e7d8790907c72b8beaf83362ac527f04 Deleted: sha256:bbbfc22ec9c4b1de66375e8c68b7ffb14964a27a1757cacb2fd9d5eed3fb2f2e Deleted: sha256:01ea25af332b46ae9cb51ca97f77a6ae8f73c9efab5c4d3484ed9709c792fc60 Deleted: sha256:4d0c6342b0f59879b314fbfd16867ed6a92583ad06e7f649e53de722af0f2156 //删完之后查看已经没有mysql镜像 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest feb5d9fea6a5 14 months ago 13.3kB centos latest 5d0da3dc9764 14 months ago 231MB //命令 docker rmi -f $(docker images -aq) //上面命令代表删除全部镜像! [root@localhost ~]# docker rmi -f $(docker images -aq) Untagged: hello-world:latest Untagged: hello-world@sha256:faa03e786c97f07ef34423fccceeec2398ec8a5759259f94d99078f264e9d7af Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412 Deleted: sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359 Untagged: centos:latest Untagged: centos@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177 Deleted: sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6 Deleted: sha256:74ddd0ec08fa43d09f32636ba91a0a3053b02cb4627c35051aff89f853606b59 //再次查询发现镜像已全部删除! [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE
三、docker的容器命令
1.查看容器
//命令 docker ps(查看正在运行的容器) [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 16c1136241dd mysql "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 3306/tcp, 33060/tcp upbeat_blackwell //命令 docker ps -a(查看所有的容器,包括正在运行和已经停止的) [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c70259707a44 centos "/bin/bash" About a minute ago Exited (0) 15 seconds ago objective_saha 16c1136241dd mysql "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 3306/tcp, 33060/tcp upbeat_blackwell
2.运行容器
//命令 docker run -it -d --name 要取的别名 镜像名:tag /bin/bash //-it 表示与容器进行交互式启动 //-d表示可后台运行容器 //--name给要运行的容器取的名 //以交互式启动mysql容器 [root@localhost ~]# docker run -it mysql /bin/bash bash-4.4# [root@localhost ~]# //以交互式启动centos容器 [root@localhost ~]# docker run -it centos /bin/bash [root@b56d0be965aa /]# [root@localhost ~]# [root@localhost ~]# //查看当前正在运行的容器 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b56d0be965aa centos "/bin/bash" 30 seconds ago Up 28 seconds reverent_williams 26b580adce05 mysql "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp, 33060/tcp jovial_johnson 16c1136241dd mysql "docker-entrypoint.s…" 11 minutes ago Up 11 minutes 3306/tcp, 33060/tcp upbeat_blackwell //命令 docker exec -it 容器id /bin/bash(以交互式进入当前正在运行的容器) [root@localhost ~]# docker exec -it b56d0be965aa /bin/bash [root@b56d0be965aa /]# [root@b56d0be965aa /]# read escape sequence //命令 docker attach 容器id(进入当前正在运行的容器) [root@localhost ~]# docker attach b56d0be965aa [root@b56d0be965aa /]# ls bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var //exit停止容器并且退出 [root@b56d0be965aa /]# exit exit [root@localhost ~]#
3.进入容器
有两种方式:①docker exec -it 容器id /bin/bash(进入正在运行的容器后悔开启一个新的终端,常用);②docker attach 容器id(进入容器后直接进行正在执行的终端,不会开启新的终端)
//命令 docker exec -it 容器id /bin/bash(以交互式进入当前正在运行的容器) [root@localhost ~]# docker exec -it b56d0be965aa /bin/bash [root@b56d0be965aa /]# [root@b56d0be965aa /]# read escape sequence //命令 docker attach 容器id(进入当前正在运行的容器) [root@localhost ~]# docker attach b56d0be965aa [root@b56d0be965aa /]# ls bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
4.退出容器
也有两种方式:①exit,这种方式会直接将当前运行的容器停止掉退出;②Ctrl+P+Q,这种不停止当前的容器进行退出。
[root@localhost ~]# docker exec -it 26b580adce05 /bin/bash //使用exit退出,直接容器停止并且退出 bash-4.4# exit exit [root@localhost ~]# [root@localhost ~]# docker exec -it 26b580adce05 /bin/bash //使用Ctrl+P+Q容器不停止退出 bash-4.4# read escape sequence [root@localhost ~]#
5.删除容器
//查看所有的容器 [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dcdbb57e7362 centos "/bin/bash" 22 seconds ago Exited (0) 14 seconds ago kind_jepsen b6bbd7a6edd2 centos "/bin/bash" 29 seconds ago Exited (0) 25 seconds ago trusting_haibt cc893fadf815 mysql "docker-entrypoint.s…" About a minute ago Exited (0) 50 seconds ago priceless_gates //命令 docker rm 容器id //删除id为dcdbb57e7362的容器 [root@localhost ~]# docker rm dcdbb57e7362 dcdbb57e7362 [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b6bbd7a6edd2 centos "/bin/bash" 45 seconds ago Exited (0) 41 seconds ago trusting_haibt cc893fadf815 mysql "docker-entrypoint.s…" About a minute ago Exited (0) About a minute ago priceless_gates //命令 docker rm -f $(docker ps -aq) //删除所有的容器 [root@localhost ~]# docker rm -f $(docker ps -aq) b6bbd7a6edd2 cc893fadf815 [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@localhost ~]#
6.启动和停止容器的操作
//查看所有的容器 [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES db9382588d60 centos "/bin/bash" 27 seconds ago Exited (0) 22 seconds ago gifted_hodgkin 4158303298d0 mysql "docker-entrypoint.s…" 45 seconds ago Exited (0) 36 seconds ago sharp_lewin 4605ab187c73 mysql "docker-entrypoint.s…" About a minute ago Exited (1) About a minute ago amazing_boyd //命令 docker start 容器id(启动容器) //启动id为db9382588d60的容器 [root@localhost ~]# docker start db9382588d60 db9382588d60 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES db9382588d60 centos "/bin/bash" About a minute ago Up 10 seconds gifted_hodgkin //命令 docker restart 容器id(重启容器) //重新启动id为4158303298d0的容器 [root@localhost ~]# docker restart 4158303298d0 4158303298d0 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES db9382588d60 centos "/bin/bash" About a minute ago Up 43 seconds gifted_hodgkin 4158303298d0 mysql "docker-entrypoint.s…" About a minute ago Up 3 seconds 3306/tcp, 33060/tcp sharp_lewin //命令 docker stop 容器id(停止当前正在运行的容器) //停止正在运行的id为db9382588d60的容器 [root@localhost ~]# docker stop db9382588d60 db9382588d60 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4158303298d0 mysql "docker-entrypoint.s…" 2 minutes ago Up 37 seconds 3306/tcp, 33060/tcp sharp_lewin //命令 docker kill 容器id(强制停止当前容器) //强制停止id为4158303298d0的容器 [root@localhost ~]# docker kill 4158303298d0 4158303298d0 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
四、其他常用命令
1.后台启动容器
//命令 docker run -d 镜像名 [root@localhost ~]# docker run -d centos 917388d45cea522f4e63a48c080cda2d394c148ad4b770f364b43e81f21dd8ea
2.查看日志
//命令 docker logs -tf --tail num 容器id //-tf 表示显示日志 //--tail num 表示显示日志的条数 //查看id为917388d45cea容器的10条日志 [root@localhost ~]# docker logs -tf --tail 10 917388d45cea
3.查看容器中的进程信息
//命令 docker top 容器id [root@localhost ~]# docker top 4158303298d0 UID PID PPID C STIME TTY TIME CMD root 11193 11175 1 11:52 ? 00:00:00 /bin/bash
4.查看镜像的元数据
//命令 docker inspect 容器id [root@localhost ~]# docker inspect 4158303298d0 [ { "Id": "4158303298d0735e82671ca7d1d6205a8503b57329483a5f98ceed129e4329d2", "Created": "2022-11-25T03:31:44.496887834Z", "Path": "docker-entrypoint.sh", "Args": [ "/bin/bash" ], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 11193, "ExitCode": 0, "Error": "", "StartedAt": "2022-11-25T03:52:56.869708722Z", "FinishedAt": "2022-11-25T03:34:31.462469568Z" }, "Image": "sha256:3842e9cdffd239649671beaec03b363b52f7b050fbb4a8869c052438408d6d2e", "ResolvConfPath": "/var/lib/docker/containers/4158303298d0735e82671ca7d1d6205a8503b57329483a5f98ceed129e4329d2/resolv.conf", "HostnamePath": "/var/lib/docker/containers/4158303298d0735e82671ca7d1d6205a8503b57329483a5f98ceed129e4329d2/hostname", "HostsPath": "/var/lib/docker/containers/4158303298d0735e82671ca7d1d6205a8503b57329483a5f98ceed129e4329d2/hosts", "LogPath": "/var/lib/docker/containers/4158303298d0735e82671ca7d1d6205a8503b57329483a5f98ceed129e4329d2/4158303298d0735e82671ca7d1d6205a8503b57329483a5f98ceed129e4329d2-json.log", "Name": "/sharp_lewin", "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, "Dns": [], "DnsOptions": [], "DnsSearch": [], "ExtraHosts": null, "GroupAdd": null, "IpcMode": "shareable", "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, "DiskQuota": 0, "KernelMemory": 0, "MemoryReservation": 0, "MemorySwap": 0, "MemorySwappiness": null, "OomKillDisable": false, "PidsLimit": 0, "Ulimits": null, "CpuCount": 0, "CpuPercent": 0, "IOMaximumIOps": 0, "IOMaximumBandwidth": 0, "MaskedPaths": [ "/proc/acpi", "/proc/kcore", "/proc/keys", "/proc/latency_stats", "/proc/timer_list", "/proc/timer_stats", "/proc/sched_debug", "/proc/scsi", "/sys/firmware" ], "ReadonlyPaths": [ "/proc/asound", "/proc/bus", "/proc/fs", "/proc/irq", "/proc/sys", "/proc/sysrq-trigger" ] }, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/1039d3baa5f729a7e8f4ded6858b6ca852325c526aef005b888073b0c3911382-init/diff:/var/lib/docker/overlay2/8ec80ff690f4586b15afa037f890f90d46ec8edc49b653d8e6cf37e569b345a4/diff:/var/lib/docker/overlay2/ab5eaa982c9b9f4c4f4847762cae2bddac7ceb75ebf370ca47e0bdabab39da2d/diff:/var/lib/docker/overlay2/de729753a32111ee635c7b0bc56a70f86957278063bde10cb422a83be19a3173/diff:/var/lib/docker/overlay2/69414c25e786d0ef1363f2b3133832c0792ad4db38be0febfbc35f6d9c597001/diff:/var/lib/docker/overlay2/f83480357e473397df976fed8edc33162c6733ae4dd9d32777cfddf0cf0ddde7/diff:/var/lib/docker/overlay2/4c03ae23ac19bac00410ab0051974ce9fec06eecbb1f8915aa9d15bfda9a68f5/diff:/var/lib/docker/overlay2/ba79579efc7eb9e63201a60e9c73217e4afa2b3ea6504e839747c8545ab3cd97/diff:/var/lib/docker/overlay2/57f5b885a0ea334b8ce49f08ad6eabe496e1c83212de35c168da1f9b91125560/diff:/var/lib/docker/overlay2/944252d188f7fa6c71ff34cb480d5f126a12c3b46751ee376be501a5059f33d8/diff:/var/lib/docker/overlay2/cfbc080088d9d5ebd099902d3773e4e959df5401f45af3dfadf2ef6b909d6b31/diff:/var/lib/docker/overlay2/c97cfb678b70718241140d09ad123c0323be818a02f8567a1cc2b071405dc6b5/diff", "MergedDir": "/var/lib/docker/overlay2/1039d3baa5f729a7e8f4ded6858b6ca852325c526aef005b888073b0c3911382/merged", "UpperDir": "/var/lib/docker/overlay2/1039d3baa5f729a7e8f4ded6858b6ca852325c526aef005b888073b0c3911382/diff", "WorkDir": "/var/lib/docker/overlay2/1039d3baa5f729a7e8f4ded6858b6ca852325c526aef005b888073b0c3911382/work" }, "Name": "overlay2" }, "Mounts": [ { "Type": "volume", "Name": "091856fdeba381af10ec3ed4025e2b564325c51fd39cb4afd840bda7d0ab60f0", "Source": "/var/lib/docker/volumes/091856fdeba381af10ec3ed4025e2b564325c51fd39cb4afd840bda7d0ab60f0/_data", "Destination": "/var/lib/mysql", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } ], "Config": { "Hostname": "4158303298d0", "Domainname": "", "User": "", "AttachStdin": true, "AttachStdout": true, "AttachStderr": true, "ExposedPorts": { "3306/tcp": {}, "33060/tcp": {} }, "Tty": true, "OpenStdin": true, "StdinOnce": true, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "GOSU_VERSION=1.14", "MYSQL_MAJOR=8.0", "MYSQL_VERSION=8.0.31-1.el8", "MYSQL_SHELL_VERSION=8.0.31-1.el8" ], "Cmd": [ "/bin/bash" ], "Image": "mysql", "Volumes": { "/var/lib/mysql": {} }, "WorkingDir": "", "Entrypoint": [ "docker-entrypoint.sh" ], "OnBuild": null, "Labels": {} }, "NetworkSettings": { "Bridge": "", "SandboxID": "9ad17eafe59ab0d20121944c52e0fb228044b446c4af2fe08b4480bf62242eac", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": { "3306/tcp": null, "33060/tcp": null }, "SandboxKey": "/var/run/docker/netns/9ad17eafe59a", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "3c1a736fdab620447f8d39e9d65d78d146d8b631288090ea376b20a53e3bda4c", "Gateway": "172.17.0.1", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "MacAddress": "02:42:ac:11:00:02", "Networks": { "bridge": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "bc8a2de62b0c1b5913a13afbc02f33e2c1c030a53ea1547077ef098d3d96c5fc", "EndpointID": "3c1a736fdab620447f8d39e9d65d78d146d8b631288090ea376b20a53e3bda4c", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:02", "DriverOpts": null } } } } ]
5.从容器中拷贝文件到宿主机
//进入centos容器 [root@localhost ~]# docker run -it centos /bin/bash [root@aa63b6c1dc9d /]# ls bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var //在centos容器的home目录下创建一个zhangsan.java文件 [root@aa63b6c1dc9d /]# cd home [root@aa63b6c1dc9d home]# touch zhangsan.java [root@aa63b6c1dc9d home]# ls zhangsan.java [root@aa63b6c1dc9d home]# [root@localhost ~]# //命令 docker cp 容器id:容器内路径 宿主机的保存路径 //将id为aa63b6c1dc9d容器中的home下的zhangsan.java文件拷贝到宿主机的/home中 [root@localhost ~]# docker cp aa63b6c1dc9d:/home/zhangsan.java /home [root@localhost ~]# cd / [root@localhost /]# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var [root@localhost /]# cd home [root@localhost home]# ls test.java zhangsan.java
docker的命令还有很多,以上是最基本的,一起努力!!!
标签:ago,容器,常用,命令,mysql,docker,root,localhost From: https://www.cnblogs.com/yzq-top/p/16924414.html