🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] <br> <br> >[info] ## 启动容器 ``` docker run ubuntu echo "hello word" ``` ![](https://img.kancloud.cn/81/19/81192f87b655dfe339bf187e6736f00e_492x41.png) 输出成功了,在输出成功后容器也停止了,这是运行单次容器的命令 <br> <br> >[info] ## 启动交互式容器 ``` docker run -i -t ubuntu /bin/bash ``` ![](https://img.kancloud.cn/bf/67/bf67e92d9cea7e820eda91a7d152baf9_547x48.png) ![](https://img.kancloud.cn/51/d0/51d08ceebd68b7c9079cc7b22f4dcc9a_646x107.png) ![](https://img.kancloud.cn/11/22/11229e1a88db4920e4b495fc8798be56_481x89.png) <br> <br> >[info] ## 查看容器 ``` docker ps [-a][-l] ``` > -a 是指列出所有的容器 > -l 是指列出最新创建的容器 如果我们直接运行`docker ps`没有执行参数时,docker直接返回当前运行的容器 <br> ``` docker ps -a ``` ![](https://img.kancloud.cn/71/44/7144b7b1f7d0cf68ce30f1629bad2b11_1124x175.png) 注意:`CONTAINER ID`是容器的唯一ID,**NAMES**是容器的名字 下面我们将检查容器,检查容器用到的命令是**docker inspect** 后面要跟着容器id或容器名字都可以 ``` docker inspect ubuntu:18.04 // 查看镜像的详细信息 [ { "Id": "sha256:d131e0fa2585a7efbfb187f70d648aa50e251d9d3b7031edf4730ca6154e221e", "RepoTags": [ "ubuntu:18.04" ], "RepoDigests": [ "ubuntu@sha256:d26d529daa4d8567167181d9d569f2a85da3c5ecaf539cace2c6223355d69981" ], "Parent": "", "Comment": "", "Created": "2019-04-26T22:21:05.100534088Z", "Container": "8a681ed429a156522e3703d03bc9be8f543afca51f828e29e8bea369b2da5ac3", "ContainerConfig": { "Hostname": "8a681ed429a1", "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", "#(nop) ", "CMD [\"/bin/bash\"]" ], "ArgsEscaped": true, "Image": "sha256:84a91c92bc7d7ffc41fdc12d50d8c205330f2c2f5f6b6725def71a46782b0ab5", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": {} }, "DockerVersion": "18.06.1-ce", "Author": "", "Config": { "Hostname": "", "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/bash" ], "ArgsEscaped": true, "Image": "sha256:84a91c92bc7d7ffc41fdc12d50d8c205330f2c2f5f6b6725def71a46782b0ab5", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": null }, "Architecture": "amd64", "Os": "linux", "Size": 101749224, "VirtualSize": 101749224, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/14c1542a6a61092a163802f3203e0512cb1fa153eca5cda828924c46822e0eaf/diff:/var/lib/docker/overlay2/3d8d8a83488a0033eeed1959ac5507e28726de2d83ba532f8f732a7281289b98/diff:/var/lib/docker/overlay2/71a99fbfabcd98c9c6f3d5aa99ccf2e837e37c293a22d01f9cf94c2e188dbadc/diff", "MergedDir": "/var/lib/docker/overlay2/50abaded2d1867213face044a814770c0d74fefc8b78b5776aa2c05c148147e3/merged", "UpperDir": "/var/lib/docker/overlay2/50abaded2d1867213face044a814770c0d74fefc8b78b5776aa2c05c148147e3/diff", "WorkDir": "/var/lib/docker/overlay2/50abaded2d1867213face044a814770c0d74fefc8b78b5776aa2c05c148147e3/work" }, "Name": "overlay2" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:604cbde1a4c8fee1b102f8b64d4f41e62d770b5f8a6b06fb809cfd873a2643c3", "sha256:5d74a98c48bcfc2d04e9d679ea095d360ac0b2f2a27312c8e95a7f5ba5341d9c", "sha256:94e5c4ea5da6d2a5e0232458e8f14a2cdba0d0f0ce1bdd8098789477c89a7f45", "sha256:7660ded5319c352f98b8b305b6bd11a501b9704f5e31d1e3b1d3da644f1c3fb8" ] }, "Metadata": { "LastTagTime": "0001-01-01T00:00:00Z" } } ] ``` <br> <br> >[info] ## 自定义容器的名字 `docker run --name=自定义名-i-t IMAGE /bin/bash` ``` docker run --name=one1 -i -t ubuntu /bin/bash ``` ![](https://img.kancloud.cn/90/a9/90a94e1f92056447e89cbac2a7cc410a_1078x184.png) 因为容器运行后会停止,我们不可能每次运行时都要建立一个容器,所以下面是解决方法 <br> <br> >[info] ## 重新启动停止的容器 以交互的方法重新启动已经停止的容器 ``` docker start [-i] 容器名称 ``` ![](https://img.kancloud.cn/4b/4e/4b4e1a57b854514960e4da882cf273c2_433x72.png) <br> <br> >[info] ## 删除已经停止的容器 使用 **`docker rm 容器名`** 命令 注意:它并不能用于正在运行中的容器 ![](https://img.kancloud.cn/c7/28/c728b3244615512bd5fe4d650b738eb0_1082x308.png)