docker客户端非常简单,我们可以直接输入docker命令来查看Docker客户端所有的命令项

[root@admin-fxr ~]# docker

Usage:    docker COMMAND

A self-sufficient runtime for containers

Options:
--config string Location of client config files (default "/root/.docker")
-D, --debug Enable debug mode
--help Print usage
-H, --host list Daemon socket(s) to connect to (default [])
-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:
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
volume Manage volumes Commands:
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes Run 'docker COMMAND --help' for more information on a command.

可以通过命令docker command --help 更深入的了解指定的Docker命令使用方法。例如我们要查看docker status 指令的具体的使用方法

[root@admin-fxr ~]# docker stats --help

Usage:    docker stats [OPTIONS] [CONTAINER...]

Display a live stream of container(s) resource usage statistics

Options:
-a, --all Show all containers (default shows just running)
--format string Pretty-print images using a Go template
--help Print usage
--no-stream Disable streaming stats and only pull the first result
[root@admin-fxr ~]#

运行WEB容器:

前面我们运行的容器并没有一些什么特殊的用处

接下来我们尝试使用docker构建一个web应用程序。

我们将在docker容器中运行一个java小程序

docker run -d -P training/webapp python app.py

参数说明:

-d:让容器在后台运行

-P:  将容器内部使用的网络端口映射到我们使用的主机上

我们写的java程序打包成一个docker镜像,然后实例化一个容器,就直接可以访问。

查看WEB应用容器的进程

[root@admin-fxr ~]# docker top mysql02
UID PID PPID C STIME TTY TIME CMD
polkitd : ? :: mysqld
root : pts/ :: /bin/bash
root : pts/ :: mysql -uroot -px xxxx
root : ? :: /bin/bash
root : pts/ :: /bin/bash
[root@admin-fxr ~]#

查看web应用程序:使用docker inspect 来查看Docker的底层信息,它会返回一个JSON文件记录着Docker容器的配置和状态信息:

[root@admin-fxr ~]# docker inspect mysql02
[
{
"Id": "bb8c5376040e126df96ceb7d9ffb254804a5e031366b0601ff820f2374eaba74",
"Created": "2018-06-11T02:02:01.869077886Z",
"Path": "docker-entrypoint.sh",
"Args": [
"mysqld"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": ,
"ExitCode": ,
"Error": "",
"StartedAt": "2018-06-11T02:02:02.177041787Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:a8a59477268d92f434d86a73b5ea6de9bf7b05d536359413e79da1feb31f87aa",
"ResolvConfPath": "/var/lib/docker/containers/bb8c5376040e126df96ceb7d9ffb254804a5e031366b0601ff820f2374eaba74/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/bb8c5376040e126df96ceb7d9ffb254804a5e031366b0601ff820f2374eaba74/hostname",
"HostsPath": "/var/lib/docker/containers/bb8c5376040e126df96ceb7d9ffb254804a5e031366b0601ff820f2374eaba74/hosts",
"LogPath": "",
"Name": "/mysql02",
"RestartCount": ,
"Driver": "overlay2",
"MountLabel": "system_u:object_r:svirt_sandbox_file_t:s0:c129,c382",
"ProcessLabel": "system_u:system_r:svirt_lxc_net_t:s0:c129,c382",
"AppArmorProfile": "",
"ExecIDs": [
"7e4eec98867d3b1f0fda4936b82c7e0ea7294f31146bf538516e44718e2caa14",
"336a9b700f39b4186804d46ff020684ecfdb8effa59aa051c99d63e7606c403e",
"05343506cbf1971a8d1c34d3d749a13830260633ceb9a7202aec4960dc038601"
],
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "journald",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"3306/tcp": [
{
"HostIp": "",
"HostPort": ""
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount":
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "",
"Cgroup": "",
"Links": null,
"OomScoreAdj": ,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": ,
"Runtime": "docker-runc",
"ConsoleSize": [
, ],
"Isolation": "",
"CpuShares": ,
"Memory": ,
"NanoCpus": ,
"CgroupParent": "",
"BlkioWeight": ,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": ,
"CpuQuota": ,
"CpuRealtimePeriod": ,
"CpuRealtimeRuntime": ,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DiskQuota": ,
"KernelMemory": ,
"MemoryReservation": ,
"MemorySwap": ,
"MemorySwappiness": -,
"OomKillDisable": false,
"PidsLimit": ,
"Ulimits": null,
"CpuCount": ,
"CpuPercent": ,
"IOMaximumIOps": ,
"IOMaximumBandwidth":
},
"GraphDriver": {
"Name": "overlay2",
"Data": {
"LowerDir": "/var/lib/docker/overlay2/7a82ad0c45a2abd460e6037ef7bb1c6424bc3bbdd3300ab0653144b3bf32607c-init/diff:/var/lib/docker/overlay2/812c628ee6a3d73b2e5625304e0cf1f5a65082870baaba31f6524ec456feb490/diff:/var/lib/docker/overlay2/91a5fbeb0c686ad843bf7730b1f773f9bd5e4f196f1f502502e082dd510ead27/diff:/var/lib/docker/overlay2/830daa3feafa22688bfb52dd81119d805ebab837ad3cedd7ac5f9d5f793783a1/diff:/var/lib/docker/overlay2/f56a48e5f09e646698d3dbdb689f08eba8dea2f49147934f67b143561918fea9/diff:/var/lib/docker/overlay2/c70b1ea7834fe8157049e8b3f3bf104b57a5c4ead0eb2dbc60149f72438e3ce9/diff:/var/lib/docker/overlay2/82a315246590c8462d5eb47edb56b6849e3c6cdc67b5c9082e0be3bfa34d1bd4/diff:/var/lib/docker/overlay2/74dfa5eaa2c884b217443ba87d7173a53bc287de3ea02e12b2944fd4676c282a/diff:/var/lib/docker/overlay2/707035914ce0c667e4aec7ddbd3e2dba3325d8c8f73344ae6736ee7c9a03c31d/diff:/var/lib/docker/overlay2/ce1b273f2ead7c2f091ad1de6f5401c3c989075c9d5368714bd02f5122e518f6/diff:/var/lib/docker/overlay2/dc78b220d2479289e41af7cf28ec60bc60030cfc5e3d38be5343bdc57828207b/diff:/var/lib/docker/overlay2/423cd24bcc5d2c4025abf3358196394bd36ef1be6943e86c80a4ffda44ac2067/diff:/var/lib/docker/overlay2/25ba916284f3a30bad8a723a0f06428fb7aa49332d2213736c79a2e9afedccdc/diff",
"MergedDir": "/var/lib/docker/overlay2/7a82ad0c45a2abd460e6037ef7bb1c6424bc3bbdd3300ab0653144b3bf32607c/merged",
"UpperDir": "/var/lib/docker/overlay2/7a82ad0c45a2abd460e6037ef7bb1c6424bc3bbdd3300ab0653144b3bf32607c/diff",
"WorkDir": "/var/lib/docker/overlay2/7a82ad0c45a2abd460e6037ef7bb1c6424bc3bbdd3300ab0653144b3bf32607c/work"
}
},
"Mounts": [
{
"Type": "volume",
"Name": "f6c63f01eb4065563842de03418bfe2d10a3645b9674d64d2f19b5bb053d6461",
"Source": "/var/lib/docker/volumes/f6c63f01eb4065563842de03418bfe2d10a3645b9674d64d2f19b5bb053d6461/_data",
"Destination": "/var/lib/mysql",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "bb8c5376040e",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"3306/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"MYSQL_ROOT_PASSWORD=123456",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.7",
"MYSQL_MAJOR=8.0",
"MYSQL_VERSION=8.0.11-1debian9"
],
"Cmd": [
"mysqld"
],
"ArgsEscaped": true,
"Image": "mysql",
"Volumes": {
"/var/lib/mysql": {}
},
"WorkingDir": "",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "08f01088ef9a536008fe9550a44df8e172ce5d86015416d69f207cb41bb51e62",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": ,
"Ports": {
"3306/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": ""
}
]
},
"SandboxKey": "/var/run/docker/netns/08f01088ef9a",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "c2f5548748c4c88696205230c47b9e4d4cbe466157cf3ded96d0147f6ebd87a8",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": ,
"IPAddress": "172.17.0.2",
"IPPrefixLen": ,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "b387fe177a81bb2eb51d29e88da05b122bf8cc5d3d4f877f819208a29d41a0c8",
"EndpointID": "c2f5548748c4c88696205230c47b9e4d4cbe466157cf3ded96d0147f6ebd87a8",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": ,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": ,
"MacAddress": "02:42:ac:11:00:02"
}
}
}
}
]
[root@admin-fxr ~]#

重启web应用程序:docker restart 容器名称

查询全部的容器:docker ps -a

查询最后一次创建的容器:docker ps -l

移除web应用程序:可以批量移除

docker rm 容器id1 容器id2 容器id3 容器id4 注意:删除容器的时候,容器必须是停止的状态,否则会报错。

Docker深入浅出3-容器管理的更多相关文章

  1. Docker深入浅出系列 | 容器初体验

    目录 Docker深入浅出系列 | 容器初体验 教程目标 预备工作 容器与虚拟化技术 什么是Docker 为什么要用Docker 事例 什么是容器镜像和容器 容器与虚拟机的区别 Vagrant与Doc ...

  2. Docker深入浅出系列 | 容器数据持久化

    Docker深入浅出系列 | 容器数据持久化 Docker已经上市很多年,不是什么新鲜事物了,很多企业或者开发同学以前也不多不少有所接触,但是有实操经验的人不多,本系列教程主要偏重实战,尽量讲干货,会 ...

  3. Docker背后的容器管理——Libcontainer深度解析

    Libcontainer 是Docker中用于容器管理的包,它基于Go语言实现,通过管理namespaces.cgroups.capabilities以及文件系统来进行容器控制.你可以使用Libcon ...

  4. Docker进阶之五:容器管理

    容器管理 一.创建容器常用选项 docker container --help 指令 描述 资源限制指令 -i, --interactive 交互式 -m,--memory 容器可以使用的最大内存量 ...

  5. Docker镜像和容器管理(二)

    Docker安装 Docker镜像管理 https://hub.docker.com/ 是公共的一个Docker镜像仓库,类似GitHub一样,上面有非常多的开源项目镜像. 可以直接在命令行搜索镜像 ...

  6. Docker 镜像与容器管理

    镜像与容器简介 Docker的大部分操作都围绕着它的三大核心概念:镜像.容器.仓库而展开.因此,准确把握这三大核心概念对于掌握Docker技术尤为重要,在docker中,我们重点关注的就是镜像和容器了 ...

  7. Docker 与 Podman 容器管理的比较

    翻译自 Paul Ferrill 2020年9月1日的文章<Compare Docker vs. Podman for container management> [1] Docker 和 ...

  8. rancher1.X+docker+k8s搭建容器管理集群

    一, 环境准备 服务器 Linux k8s-m -.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Li ...

  9. Docker深入浅出3-镜像管理

    当运行容器的时候,使用的镜像如果在本地中不存在,docker就会自动从docker镜像仓库中下载,默认是从dockerhub公共镜像源下载. 1:镜像列表 我们可以使用docker images [r ...

随机推荐

  1. rpmdb: unable to join the environment的问题解决

    今天笔者在Centos 6.3上使用yum安装lsof软件时,报如下错误: [root@ ~]# yum install lsof -y rpmdb: unable to join the envir ...

  2. iOS教程:Core Data数据持久性存储基础教程

    目录[-] 创建Core Data工程 创建数据模型 测试我们的数据模型 来看看SQL语句的真面目 自动生成的模型文件 创建一个表视图 之后看些什么? 就像我一直说的,Core Data是iOS编程, ...

  3. 基础笔记1(进制,浮点,递归,floor,round和ceil)

    1,进制默认是十进制 0开头 8进制 0x     16进制 0b     2进制 2,long 的范围是19位数字.int范围是21亿左右,short 是三万二千左右. 超过int范围的long类型 ...

  4. yii的安装

    1.安装composer windows系统直接下载Composer-Setup.exe 运行安装. 2.安装Composer asset plugin composer安装完成后,在一个可通过web ...

  5. poj3614 Sunscreen【贪心】

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11772   Accepted: 4143 Descri ...

  6. 2.3AutoEncoder

    AutoEncoder是包含一个压缩和解压缩的过程,属于一种无监督学习的降维技术. 神经网络接受大量信息,有时候接受的数据达到上千万,可以通过压缩 提取原图片最具有代表性的信息,压缩输入的信息量,在将 ...

  7. int float 的具体的取值范围取决于具体的机器 整数除法舍位 整形(int)也可以用于存储字符型数据

    int  通常为16位  存储单元 float  通常为32位 取决于具体的机器 #include main() { int fathr,celsius; int lower,upper,step; ...

  8. Qt中容器类应该如何存储对象(对象加入到容器时会发生拷贝,容器析构时,容器内的对象也会析构)

    Qt提供了丰富的容器类型,如:QList.QVector.QMap等等.详细的使用方法可以参考官方文档,网上也有很多示例文章,不过大部分文章的举例都是使用基础类型:如int.QString等.如果我们 ...

  9. 改革春风吹满地---hdu2036(多边形用差积求面积)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2036 #include<iostream> #include<stdio.h> ...

  10. vue中给请求到的数据对象加属性问题

    今天发现了个很奇怪的问题,我在做一个:点击列表  使点中的列表项变色的功能,而且是多个大列表项,在每个大列表项里点击切换列表项的时候不影响其他大列表项的选项. 解决思路,因为这些大列表项是请求到的数据 ...