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 下 ...
随机推荐
- Alienware R8外星人台式机安装双系统(WIN10+Ubuntu)的总结
新电脑终于到了,然而外星人的系统比较特殊,很多东西和别的品牌(包括DELL)不一样, 同时NVIDIA显卡也带来了很多问题.重装了十几遍,查阅了上百篇文章后之后终于搞定了双系统. 其实核心问题很傻,就 ...
- ccf-路径解析201604-3
C++没有split函数 但是有一个简单的方法,利用stringstream构建; 然后这道题就很简单啦 还要注意不能用cin 因为有空行的存在 #include <bits/stdc++.h& ...
- appscan使用教程(全)
链接图文来源:https://www.cnblogs.com/ZoeLiang/p/10198361.html 一.下载与破解 1.下载Appscan:http://download2.boulder ...
- ewfwefwefe
qwdefwef fwefwef
- Springboot 使用过滤器进行加密解密(二)
之前写过一篇关于过滤器实现加密解密功能的文章,但是在实际开发业务中发现,还是有一些问题的,在此特地说明. 第一:过滤器走两遍的问题: 1.过滤器上,添加了两个注解 第一个:@Compent 将此F ...
- 7th week blog
DOM:Document Object Model(文档对象模型) Document Object Model的历史可以追溯至1990年代后期微软与Netscape的“浏览器大战”,双方为了在Java ...
- Spring MVC中一般类使用service
在Spring MVC中,Controller中使用service只需使用注解@Resource就行,但是一般类(即不使用@Controller注解的类)要用到service时,可用如下方法: 1.S ...
- tornado--启动
tornado--启动 from tornado import web from tornado import ioloop from tornado.httpserver import HTTPSe ...
- 熟悉 JUnit 测试
2.1 Mooctest 使用心得 web Ide挺方便,就是很慢.mooctest很方便入门软件测试,但是里面的题目还是不多. 2.2 Junit 编写代码经验总结 1.首先要熟悉junit中经常使 ...
- Educational Codeforces Round 54 (Rated for Div. 2) D:Edge Deletion
题目链接:http://codeforces.com/contest/1076/problem/D 题意:给一个n个点,m条边的无向图.要求保留最多k条边,使得其他点到1点的最短路剩余最多. 思路:当 ...