docker容器的常用操作
创建容器
[root@mydocker ~]# docker create --name test_create -ti ubuntu
1d13990eea0d3f282a0f7d5589f40e49394d8fa7a766c95cc9b95ebf17deeb7f
[root@mydocker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1d13990eea0d ubuntu "/bin/bash" seconds ago Created test_create
ff2f56ca3a73 d3ae5b7a2ce8 "bash" hours ago Exited () hours ago tender_ardinghelli
e2ee7db10156 ubuntu "bash" hours ago Exited () hours ago objective_booth
51e2940a5804 ubuntu "echo 'HI you hao a'" hours ago Exited () hours ago musing_hawking
9d8caf15e8f6 hello-world "/hello" hours ago Exited () hours ago cranky_stonebraker
[root@mydocker ~]#
[root@mydocker ~]# docker run -ti -d --name test_network ubuntu bash
bc45e45234057e781c4b0b0c3c802d03f382fb2e59549433cb0889f1c5afa224
[root@mydocker ~]# docker exec -ti test_network bash
root@bc45e4523405:/# ifconfig
bash: ifconfig: command not found
root@bc45e4523405:/# cat /etc/hosts
127.0.0.1 localhost
:: localhost ip6-localhost ip6-loopback
fe00:: ip6-localnet
ff00:: ip6-mcastprefix
ff02:: ip6-allnodes
ff02:: ip6-allrouters
172.17.0.2 bc45e4523405
root@bc45e4523405:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root : ? :: bash
root : ? :: bash
root : ? :: ps -ef
root@bc45e4523405:/#
[root@mydocker ~]# docker run -ti --name test_finish ubuntu echo "hi sali"
hi sali
[root@mydocker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1477720733ed ubuntu "echo 'hi sali'" minutes ago Exited () minutes ago test_finish
bc45e4523405 ubuntu "bash" minutes ago Up minutes test_network
1d13990eea0d ubuntu "/bin/bash" minutes ago Created test_create
ff2f56ca3a73 d3ae5b7a2ce8 "bash" hours ago Exited () hours ago tender_ardinghelli
e2ee7db10156 ubuntu "bash" hours ago Exited () hours ago objective_booth
51e2940a5804 ubuntu "echo 'HI you hao a'" hours ago Exited () hours ago musing_hawking
9d8caf15e8f6 hello-world "/hello" hours ago Exited () hours ago cranky_stonebraker
[root@mydocker ~]#
[root@mydocker ~]# docker run -t -i ubuntu /bin/bash
root@3b72a81646ce:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@3b72a81646ce:/# pwd
/
root@3b72a81646ce:/# exit
exit
[root@mydocker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3b72a81646ce ubuntu "/bin/bash" 19 seconds ago Exited (0) 7 seconds ago amazing_bartik
1477720733ed ubuntu "echo 'hi sali'" 8 minutes ago Exited (0) 8 minutes ago test_finish
bc45e4523405 ubuntu "bash" 13 minutes ago Up 13 minutes test_network
1d13990eea0d ubuntu "/bin/bash" 38 minutes ago Created test_create
ff2f56ca3a73 d3ae5b7a2ce8 "bash" 5 hours ago Exited (0) 5 hours ago tender_ardinghelli
e2ee7db10156 ubuntu "bash" 6 hours ago Exited (0) 6 hours ago objective_booth
51e2940a5804 ubuntu "echo 'HI you hao a'" 6 hours ago Exited (0) 6 hours ago musing_hawking
9d8caf15e8f6 hello-world "/hello" 23 hours ago Exited (0) 23 hours ago cranky_stonebraker
[root@mydocker ~]#
[root@mydocker ~]# docker run -d --name test_daemon ubuntu /bin/sh -c "while true;do echo hello guet;sleep 1;done"
866ce2b92ac56730ba7625da5bd47a21f8b4f4341c105654a42ef56a09e36c0a
[root@mydocker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
866ce2b92ac5 ubuntu "/bin/sh -c 'while..." seconds ago Up seconds test_daemon
bc45e4523405 ubuntu "bash" minutes ago Up minutes test_network
终止容器
[root@mydocker ~]# docker stop test_daemon
test_daemon
[root@mydocker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
866ce2b92ac5 ubuntu "/bin/sh -c 'while..." minutes ago Exited () seconds ago test_daemon
3b72a81646ce ubuntu "/bin/bash" minutes ago Exited () minutes ago amazing_bartik
1477720733ed ubuntu "echo 'hi sali'" minutes ago Exited () minutes ago test_finish
bc45e4523405 ubuntu "bash" minutes ago Up minutes test_network
1d13990eea0d ubuntu "/bin/bash" About an hour ago Created test_create
ff2f56ca3a73 d3ae5b7a2ce8 "bash" hours ago Exited () hours ago tender_ardinghelli
e2ee7db10156 ubuntu "bash" hours ago Exited () hours ago objective_booth
51e2940a5804 ubuntu "echo 'HI you hao a'" hours ago Exited () hours ago musing_hawking
9d8caf15e8f6 hello-world "/hello" hours ago Exited () hours ago cranky_stonebraker
进入容器
[root@mydocker ~]# docker run -d --name test_ti ubuntu /bin/sh -c "while true;do echo hello guet;sleep 1;done"
c1839dfd85031e7dfa786f236701b523c5334b7b6c3d0b4eeb97ad3419dd266d
[root@mydocker ~]# docker exec -i -t test_ti bash
root@c1839dfd8503:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root : ? :: /bin/sh -c while true;do echo hello guet;sleep ;done
root : ? :: bash
root : ? :: sleep
root : ? :: ps -ef
root@c1839dfd8503:/# exit
exit
[root@mydocker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c1839dfd8503 ubuntu "/bin/sh -c 'while..." seconds ago Up seconds test_ti
bc45e4523405 ubuntu "bash" About an hour ago Up About an hour test_network
[root@mydocker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c1839dfd8503 ubuntu "/bin/sh -c 'while..." seconds ago Up seconds test_ti
866ce2b92ac5 ubuntu "/bin/sh -c 'while..." minutes ago Exited () minutes ago test_daemon
3b72a81646ce ubuntu "/bin/bash" About an hour ago Exited () About an hour ago amazing_bartik
1477720733ed ubuntu "echo 'hi sali'" About an hour ago Exited () About an hour ago test_finish
bc45e4523405 ubuntu "bash" About an hour ago Up About an hour test_network
1d13990eea0d ubuntu "/bin/bash" About an hour ago Created test_create
ff2f56ca3a73 d3ae5b7a2ce8 "bash" hours ago Exited () hours ago tender_ardinghelli
e2ee7db10156 ubuntu "bash" hours ago Exited () hours ago objective_booth
51e2940a5804 ubuntu "echo 'HI you hao a'" hours ago Exited () hours ago musing_hawking
9d8caf15e8f6 hello-world "/hello" hours ago Exited () hours ago cranky_stonebraker
[root@mydocker ~]#
删除容器
[root@mydocker ~]# docker rm test_ti
Error response from daemon: You cannot remove a running container c1839dfd85031e7dfa786f236701b523c5334b7b6c3d0b4eeb97ad3419dd266d.
Stop the container before attempting removal or force remove
[root@mydocker ~]# docker stop test_ti
test_ti
[root@mydocker ~]# docker rm test_ti
test_ti
[root@mydocker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
866ce2b92ac5 ubuntu "/bin/sh -c 'while..." About an hour ago Exited () minutes ago test_daemon
3b72a81646ce ubuntu "/bin/bash" About an hour ago Exited () About an hour ago amazing_bartik
1477720733ed ubuntu "echo 'hi sali'" About an hour ago Exited () About an hour ago test_finish
bc45e4523405 ubuntu "bash" About an hour ago Up About an hour test_network
1d13990eea0d ubuntu "/bin/bash" hours ago Created test_create
ff2f56ca3a73 d3ae5b7a2ce8 "bash" hours ago Exited () hours ago tender_ardinghelli
e2ee7db10156 ubuntu "bash" hours ago Exited () hours ago objective_booth
51e2940a5804 ubuntu "echo 'HI you hao a'" hours ago Exited () hours ago musing_hawking
9d8caf15e8f6 hello-world "/hello" hours ago Exited () hours ago cranky_stonebraker
[root@mydocker ~]#
root@mydocker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bc45e4523405 ubuntu "bash" About an hour ago Up About an hour test_network
[root@mydocker ~]# docker rm -f test_network
test_network
[root@mydocker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@mydocker ~]#
导入和导出容器
[root@mydocker ~]# docker run --name test_export -ti ubuntu bash
root@04b7794db11c:/# echo "hello world hadoop docker" > export.txt
root@04b7794db11c:/# ls
bin boot dev etc export.txt home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@04b7794db11c:/# cat export.txt
hello world hadoop docker
root@04b7794db11c:/# exit
exit
[root@mydocker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
04b7794db11c ubuntu "bash" seconds ago Exited () seconds ago te_export
866ce2b92ac5 ubuntu "/bin/sh -c 'while..." About an hour ago Exited () minutes ago test_daemon
3b72a81646ce ubuntu "/bin/bash" About an hour ago Exited () About an hour ago amazing_bartik
1477720733ed ubuntu "echo 'hi sali'" About an hour ago Exited () About an hour ago test_finish
1d13990eea0d ubuntu "/bin/bash" hours ago Created test_create
ff2f56ca3a73 d3ae5b7a2ce8 "bash" hours ago Exited () hours ago tender_ardinghelli
e2ee7db10156 ubuntu "bash" hours ago Exited () hours ago objective_booth
51e2940a5804 ubuntu "echo 'HI you hao a'" hours ago Exited () hours ago musing_hawking
9d8caf15e8f6 hello-world "/hello" hours ago Exited () hours ago cranky_stonebraker
[root@mydocker ~]# docker export test_export > export.tar
Error response from daemon: No such container: test_export
[root@mydocker ~]# docker export te_export > export.tar
[root@mydocker ~]# ls
anaconda-ks.cfg export.tar initial-setup-ks.cfg test.tar
[root@mydocker ~]#
[root@mydocker ~]# cat export.tar | docker import - dajiangtai/testimport:latest
sha256:6f35c73d51efe8cb0385d08d37b9f02f8eed4d03d8e215b6e7a3cedb2af3e7ec
[root@mydocker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dajiangtai/testimport latest 6f35c73d51ef seconds ago .8MB
/test latest d3ae5b7a2ce8 hours ago .8MB
gong/test latest d3ae5b7a2ce8 hours ago .8MB
gongstudy/test2 latest d3ae5b7a2ce8 hours ago .8MB
root/test latest d3ae5b7a2ce8 hours ago .8MB
ubuntu latest ea4c82dcd15a weeks ago .8MB
hello-world latest 4ab4c602aa5e weeks ago .84kB
[root@mydocker ~]#
[root@mydocker ~]# docker run -ti dajiangtai/testimport bash
root@891713e46dec:/# ls
bin boot dev etc export.txt home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@891713e46dec:/# cat export.txt
hello world hadoop docker
root@891713e46dec:/# exit
exit
[root@mydocker ~]#
docker容器的常用操作的更多相关文章
- 一文了解Docker容器技术的操作
一文了解Docker容器技术的操作 前言一.Docker是什么二.Docker的安装及测试Docker的安装Docker的Hello world测试三.Docker的常见操作镜像的基本操作容器的基本操 ...
- Docker镜像与容器的常用操作
Docker镜像加速配置:Docker镜像常用操作:Dcoker容器常用操作. 镜像加速器 国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器.国内很多云服务商都提供了国内加 ...
- centos7下安装docker(8.3容器的常用操作)
yu我们之前已经学习了如何运行容器docker run,也学习了如何进入容器docker attach和docker exec,下面我们来学习容器的其他操作: stop/start/restart 1 ...
- Docker安装及常用操作
Docker简介: Docker是一个轻量级容器技术,类似于虚拟机技术,但性能远远高于虚拟机,Docker支持将软件编译成一个镜像(image),在这个镜像中做好对软件的各种配置,然后可以运行这个镜像 ...
- docker 容器管理常用命令
Docker 容器管理: docker create -it centos //这样可以创建一个容器,但该容器并没有启动: create Create a new container 创建一个容器: ...
- Docker介绍及常用操作演示(一)--技术流ken
Docker简介 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互 ...
- docker的一些常用操作
镜像:一个打包好的应用,还有应用运行的系统.资源.配置等容器:镜像的实例,一个镜像可以有一个或多个实例(容器)对docker容器的变更时写到容器的文件系统的,而不是写到docker镜像中的,可以用一个 ...
- Docker介绍及常用操作演示(一)
Docker简介 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互 ...
- Docker 镜像的常用操作
镜像作为 Docker 三大核心概念中,最重要的一个关键词,它有很多操作,是您想学习容器技术不得不掌握的.本文将带您一步一步,图文并重,上手操作来学习它. 目录 一 Docker 下载镜像 1.1 下 ...
随机推荐
- pytorch查看模型weight与grad
在用pdb debug的时候,有时候需要看一下特定layer的权重以及相应的梯度信息,如何查看呢? 1. 首先把你的模型打印出来,像这样 2. 然后观察到model下面有module的key,modu ...
- chm提取
Python读写CHM文件 7z 可以将chm解包为HTML
- Learning Structured Representation for Text Classification via Reinforcement Learning 学习笔记
Representation learning : 表征学习,端到端的学习 pre-specified 预先指定的 demonstrate 论证;证明,证实;显示,展示;演示,说明 attempt ...
- android 判断横竖屏的方法(转)
public boolean isScreenChange() { Configuration mConfiguration = this.getResources().getConfiguratio ...
- Dictionary用法
https://www.cgjoy.com/thread-106639-1-1.html 1.新建字典,添加元素 dictionary<string,string>dic=newdict ...
- JAVA第九次作业
JAVA第九次作业 (一)学习总结 1.用思维导图对javaIO操作的学习内容进行总结. 参考资料: XMind. 2.下面的程序实现了文件的拷贝,但采用的是一个字节一个字节的读写方式,效率很低.使用 ...
- swiper插件使用遇到的一点小问题
最近做移动端开发 给出的静态页使用了Swiper,用的是4.0.3版本,应该是比较新的. 静态页这种东西,一般就是给你个雏形,设计部虽然使用了这个插件,但毕竟这个活儿毕竟还是得开发人员来干,所以,静态 ...
- 2018-2019-2 20165313 Exp2 后门原理与实践
实践基础问题回答 (1)例举你能想到的一个后门进入到你系统中的可能方式? 应用程序设定后门,用户安装后,后门就可以进入.例如课堂上讲到的百度. (2)例举你知道的后门如何启动起来(win及linux) ...
- JDK11&12 新特性学习
- 使用 Flask-Docs 自动生成 Api 文档
影响我写文档的原因可能是代码和文档分离,有时候写完代码会忘记补文档,而且不能及时查看,使用 Flask-Docs 可以解决我的问题,这个插件可以根据代码注释生成文档页面,代码注释改动文档可以及时更新, ...