docker容器命令(一)
容器命令
创建容器:
docker run
参数:
- -it 交互
- -d 后台
- –name 容器名
- -p 主机端口:容器端口 (主机端口映射到docker端口)
docker run --name centos1 -it centos /bin/bash
docker ps 显示容器信息
参数:
- -a
- -q 只显示容器id
[root@tanqi ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ad5b2b6854f centos "/bin/bash" About a minute ago Up About a minute centos1
3c45403d051a centos "/bin/bash" 14 minutes ago Exited (0) 14 minutes ago frosty_cannon
[root@tanqi ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ad5b2b6854f centos "/bin/bash" About a minute ago Up About a minute centos1
[root@tanqi ~]# docker ps -q
8ad5b2b6854f
[root@tanqi ~]# docker ps -aq
8ad5b2b6854f
- 启动容器
`docker start -i 容器id/容器名
Options:
-a, --attach Attach STDOUT/STDERR and forward signals
–detach-keys string Override the key sequence for detaching a container
-i, --interactive Attach container’s STDIN
- 进入容器
docker exec -it 容器id/容器名 /bin/bash#启动新终端
[root@tanqi ~]# docker exec -it centos1 /bin/bash
docker attach 容器id/容器名//进入容器直接进入正在执行
[root@tanqi ~]# docker attach centos1
[root@8ad5b2b6854f /]#
- 退出容器
exit退出并停止
crtl+P+Q 退出 不停止
- 从容器拷贝到主机
docker cp 容器id:容器路径 主机路径
[root@tanqi ~]# docker cp centos1:/home/test /root
[root@tanqi ~]# ls
dump.rdb f1.txt install.sh study test
-v 卷的技术
其他命令
- 后台创建启动容器:
docker run -d centos# 可能会停止 因为没有前台进程
- 日志
docker logs --tail 10 容器id/容器名//看后10条Options:
–details Show extra details provided to logs
-f, --follow Follow log output 新log会加
–since string Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for
42 minutes)
-n, --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:37Z) or relative (e.g. 42m
for 42 minutes)
[root@tanqi ~]# docker logs --tail 2 centos1
[root@8ad5b2b6854f home]# ls
test
[root@tanqi ~]# docker logs -f --tail 2 centos1
[root@8ad5b2b6854f home]# ls
test
...等待刷新
- 运行脚本
docker run -d 容器di /bin/sh -c "脚本语言"
- 进程信息
docker top 容器id/容器名
[root@tanqi ~]# docker top centos1
UID PID PPID C STIME TTY TIME CMD
root 15054 15033 0 15:30 pts/0 00:00:00 /bin/bash
- 元数据
docker inspect 容器id/容器名
小结
容器命令
创建容器:
docker run
参数
-it 交互
-d 后台
–name 容器名
docker run --name centos1 -it centos /bin/bash
docker ps 显示容器信息
参数:
- -a
- -q 只显示容器id
[root@tanqi ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ad5b2b6854f centos "/bin/bash" About a minute ago Up About a minute centos1
3c45403d051a centos "/bin/bash" 14 minutes ago Exited (0) 14 minutes ago frosty_cannon
[root@tanqi ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ad5b2b6854f centos "/bin/bash" About a minute ago Up About a minute centos1
[root@tanqi ~]# docker ps -q
8ad5b2b6854f
[root@tanqi ~]# docker ps -aq
8ad5b2b6854f
- 启动容器
`docker start -i 容器id/容器名
Options:
-a, --attach Attach STDOUT/STDERR and forward signals
–detach-keys string Override the key sequence for detaching a container
-i, --interactive Attach container’s STDIN
- 进入容器
docker exec -it 容器id/容器名 /bin/bash#启动新终端
[root@tanqi ~]# docker exec -it centos1 /bin/bash
docker attach 容器id/容器名//进入容器直接进入正在执行
[root@tanqi ~]# docker attach centos1
[root@8ad5b2b6854f /]#
- 退出容器
exit退出并停止
crtl+P+Q 退出 不停止
- 从容器拷贝到主机
docker cp 容器id:容器路径 主机路径
[root@tanqi ~]# docker cp centos1:/home/test /root
[root@tanqi ~]# ls
dump.rdb f1.txt install.sh study test
-v 卷的技术
其他命令
- 后台创建启动容器:
docker run -d centos# 可能会停止 因为没有前台进程
- 日志
docker logs --tail 10 容器id/容器名//看后10条Options:
–details Show extra details provided to logs
-f, --follow Follow log output 新log会加
–since string Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for
42 minutes)
-n, --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:37Z) or relative (e.g. 42m
for 42 minutes)
[root@tanqi ~]# docker logs --tail 2 centos1
[root@8ad5b2b6854f home]# ls
test
[root@tanqi ~]# docker logs -f --tail 2 centos1
[root@8ad5b2b6854f home]# ls
test
...等待刷新
- 运行脚本
docker run -d 容器di /bin/sh -c "脚本语言"
- 进程信息
docker top 容器id/容器名
[root@tanqi ~]# docker top centos1
UID PID PPID C STIME TTY TIME CMD
root 15054 15033 0 15:30 pts/0 00:00:00 /bin/bash
- 元数据
docker inspect 容器id/容器名
小结
官网的图

docker容器命令(一)的更多相关文章
- docker容器命令2
docker容器命令2 启动守护式容器 docker run -d 镜像名字 [root@tzh ~]# docker images REPOSITORY TAG IMAGE ID CREATED S ...
- docker容器命令1
docker容器命令 新建并启动容器命令 docker run INAME(镜像名字) 语法:docker run [OPTIONS] INAME [COMMAND] 例子:docker run -i ...
- Docker容器命令
★根本前提:本地主机有镜像才能创建容器 ⒈docker run [Options] 镜像名称或镜像ID [Command] [Arg...] 用途:利用镜像创建容器实例 Options说明(常用):注 ...
- Docker 容器命令大全
容器命令: 命令 描述 attach 将本地标准输入,输出和错误流转到到正在运行的容器 build 从Dockerfile构建映像 commit 根据容器的更改创建新镜像 cp 在容器和本地文件系统之 ...
- docker 容器命令
语法docker run [OPTIONS] IMAGE [COMMAND] [ARG...] OPTIONS说明: -a stdin: 指定标准输入输出内容类型,可选 STDIN/STDOUT/ST ...
- kubectl&docker容器命令行窗口太小
#k8s kubectl exec -ti busybox env COLUMNS=$COLUMNS LINES=$LINES bash #k8s example kubectl exec -t ...
- 进入docker 容器命令行
#!/bin/bash CNAME=$1 CPID=$(docker inspect --format "{{.State.Pid}}" $CNAME) nsenter --tar ...
- docker的使用 一容器命令
Docker容器命令 前提 执行容器的前提是有镜像 . #创建并启动容器 docker run [options] images [command][args] // option 的说明 --nam ...
- Docker容器操作中常用命令集合
docker pull 从仓库获取所需要的镜像 docker images 显示本地已有的镜像. docker commit 提交更新后的副本. docker build 创建一个新的镜像 ADD 复 ...
随机推荐
- 虚拟机启动jenkins,访问提示:该Jenkins实例似乎已离线
ubuntu虚拟机使用java命令启动jenkins,本地访问提示:该Jenkins实例似乎已离线. https://www.cnblogs.com/du-hong/p/10655635.html 没 ...
- python mysql增加改查
#python mysql增加改查,方便日后copy/paste .......... 1 #encoding: UTF-8 2 import pymysql 3 # # 打开数据库连接 4 db = ...
- 虚拟机安装配置centos7
安装 https://blog.csdn.net/babyxue/article/details/80970526 主机环境预设 更换国内yum源 epel源 https://www.cnblogs. ...
- IDEA连接Mysql数据库之后,在Mapper.xml编写SQL时不会自动提示表信息问题(非常详细!)
1.首先得连接上数据库 (一)点击IDEA右侧数据库模块 (二)选择MySql进行连接 (三)填写数据库相关配置 (四)重点!!! 这个时候点击测试连接是连接不上的,需要设置时区 (按照如下设置) ( ...
- null与undefined到底有啥区别?
话不多说,直接先上结论: null 和 undefined 基本相同,只有细微差别 null 是表示缺少的标识,指示变量未指向任何对象,转为数值为 0 undefined 表示 "缺少值&q ...
- PHP审计之POP链挖掘
PHP审计之POP链挖掘 前言 续上文中的php反序列化,继续来看,这个POP的挖掘思路.在其中一直构思基于AST去自动化挖掘POP链,迫于开发能力有限.没有进展,随后找到了一个别的师傅已经实现好的项 ...
- 洛谷2900 [USACO08MAR]土地征用Land Acquisition (斜率优化+dp)
自闭的一批....为什么斜率优化能这么自闭. 首先看到这个题的第一想法一定是按照一个维度进行排序. 那我们不妨直接按照\(h_i\)排序. 我们令\(dp[i]\)表示到了第\(i\)个矩形的答案是多 ...
- FastAPI 学习之路(七)字符串的校验
系列文章: FastAPI 学习之路(一)fastapi--高性能web开发框架 FastAPI 学习之路(二) FastAPI 学习之路(三) FastAPI 学习之路(四) FastAPI 学习之 ...
- Visual Studio Debug only user code with Just My Code
Debug only user code with Just My Code By default, the debugger skips over non-user code (if you wan ...
- 【UE4】虚幻引擎技术直播汇总(含中英文直播)
B站虚幻引擎官方账号 中文直播 [中文直播]第35期 | 使用GIS在UE中创造真实地球风貌 | Epic 周澄清 [中文直播]第34期 | 包教包会的Epic MegaGrants申请之道 | Ep ...