Docker常用命令
今天我们继续来学Docker的命令/(ㄒoㄒ)/~~
docker inspect
- 语法:docker inspect ContainerId/NAME
- 作用:获取容器/镜像的元数据
例子:
docker inspect elasticsearch:7.7.1 [
{
"Id": "sha256:830a894845e39d20e413d8a824ba1f7562d76a02cf9a85a8b6d1d9d47a4d5dd3",
"RepoTags": [
"elasticsearch:7.7.1"
],
"RepoDigests": [
"elasticsearch@sha256:dff614393a31b93e8bbe9f8d1a77be041da37eac2a7a9567166dd5a2abab7c67"
],
"Parent": "",
"Comment": "",
"Created": "2020-05-28T16:35:24.240322241Z",
"Container": "a5f5c958558a9b015c3b57d3d625c478fd2c1d37e62dad4cb51a23862b59dfdb",
"ContainerConfig": {
"Hostname": "a5f5c958558a",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"9200/tcp": {},
"9300/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/share/elasticsearch/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"ELASTIC_CONTAINER=true"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"eswrapper\"]"
],
"Image": "sha256:9a105291472c67a41cd4ed711e3db5e87f6073550fd1402f9cb8e70597abe019",
"Volumes": null,
"WorkingDir": "/usr/share/elasticsearch",
"Entrypoint": [
"/tini",
"--",
"/usr/local/bin/docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "2020-05-28T16:30:01.040088Z",
"org.label-schema.license": "Elastic-License",
"org.label-schema.name": "Elasticsearch",
"org.label-schema.schema-version": "1.0",
"org.label-schema.url": "https://www.elastic.co/products/elasticsearch",
"org.label-schema.usage": "https://www.elastic.co/guide/en/elasticsearch/reference/index.html",
"org.label-schema.vcs-ref": "ad56dce891c901a492bb1ee393f12dfff473a423",
"org.label-schema.vcs-url": "https://github.com/elastic/elasticsearch",
"org.label-schema.vendor": "Elastic",
"org.label-schema.version": "7.7.1",
"org.opencontainers.image.created": "2020-05-28T16:30:01.040088Z",
"org.opencontainers.image.documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/index.html",
"org.opencontainers.image.licenses": "Elastic-License",
"org.opencontainers.image.revision": "ad56dce891c901a492bb1ee393f12dfff473a423",
"org.opencontainers.image.source": "https://github.com/elastic/elasticsearch",
"org.opencontainers.image.title": "Elasticsearch",
"org.opencontainers.image.url": "https://www.elastic.co/products/elasticsearch",
"org.opencontainers.image.vendor": "Elastic",
"org.opencontainers.image.version": "7.7.1"
}
},.......
docker cp
-
语法:docker cp CONTAINER:SRC_PATH DEST_PATH
-
作用:将容器中文件拷往主机
-
语法:docker cp SRC_PATH CONTAINER:DEST_PATH
-
作用:将主机的文件拷往容器
例子:将本地的elasticsearch.yml拷往容器的/usr/share/elasticsearch/co
nfig/ 文件夹
docker cp E:/elasticsearch-7.3.2-no-jdk-windows-x86_64/elasticsearch-7.3.2/config/elasticsearch.yml 83bba1b53fff:/usr/share/elasticsearch/co
nfig/
例子:将容器的elasticsearch.yml拷往主机的桌面
docker cp 83bba1b53fff:/usr/share/elasticsearch/config/elasticsearch.yml C:/Users/ZJ/Desktop/
docker logs
- 命令: docker logs [OPTIONS] CONTAINERID
- 作用:获取容器的日志
选项 | 作用 |
---|---|
–details | 显示更多的信息 |
-f, --follow | 跟踪实时日志 |
–since string | 显示自某个timestamp之后的日志,或相对时间,如42m(即42分钟) |
–tail string | 从日志末尾显示多少行日志, 默认是all |
-t, --timestamps | 显示时间戳 |
–until string | 显示自某个timestamp之前的日志,或相对时间,如42m(即42分钟) |
例子:跟踪实时日志,只显示最后5行
docker logs -f -t --tail=5 83bba1b53fff
例子:显示最近30分钟的日志
docker logs --since=30m 83bba1b53fff
例子:显示2020年7月1日以后的日志
docker logs -t --since="2020-07-01" 83bba1b53fff
例子:显示2020年7月1日至2020年7月2日时间段的日志
docker logs -t --since="2020-07-01" --until "2020-07-02" 83bba1b53fff
docker exec
- 命令:docker exec [OPTIONS] CONTAINER COMMAND [ARG…]
- 作用:在运行的容器中执行命令
选项 | 作用 |
---|---|
-d | 在后台运行 |
-i | 即使没有附加也保持STDIN 打开 |
-t | 分配一个伪终端 |
例子
$ docker exec -it 941a819f5832 echo -e "Hello nginx"
Hello nginx
命令小备份:
docker exec 83bba1b53fff cat /usr/share/elasticsearch/config/elasticsearch.yml
$ docker run --name=test_es -d -p 9200:9200 -p 9300:9300 docker.io/elasticsearch:7.7.1