创建容器

[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容器的常用操作的更多相关文章

  1. 一文了解Docker容器技术的操作

    一文了解Docker容器技术的操作 前言一.Docker是什么二.Docker的安装及测试Docker的安装Docker的Hello world测试三.Docker的常见操作镜像的基本操作容器的基本操 ...

  2. Docker镜像与容器的常用操作

    Docker镜像加速配置:Docker镜像常用操作:Dcoker容器常用操作. 镜像加速器 国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器.国内很多云服务商都提供了国内加 ...

  3. centos7下安装docker(8.3容器的常用操作)

    yu我们之前已经学习了如何运行容器docker run,也学习了如何进入容器docker attach和docker exec,下面我们来学习容器的其他操作: stop/start/restart 1 ...

  4. Docker安装及常用操作

    Docker简介: Docker是一个轻量级容器技术,类似于虚拟机技术,但性能远远高于虚拟机,Docker支持将软件编译成一个镜像(image),在这个镜像中做好对软件的各种配置,然后可以运行这个镜像 ...

  5. docker 容器管理常用命令

    Docker 容器管理: docker create -it centos //这样可以创建一个容器,但该容器并没有启动: create Create a new container 创建一个容器: ...

  6. Docker介绍及常用操作演示(一)--技术流ken

    Docker简介 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互 ...

  7. docker的一些常用操作

    镜像:一个打包好的应用,还有应用运行的系统.资源.配置等容器:镜像的实例,一个镜像可以有一个或多个实例(容器)对docker容器的变更时写到容器的文件系统的,而不是写到docker镜像中的,可以用一个 ...

  8. Docker介绍及常用操作演示(一)

    Docker简介 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互 ...

  9. Docker 镜像的常用操作

    镜像作为 Docker 三大核心概念中,最重要的一个关键词,它有很多操作,是您想学习容器技术不得不掌握的.本文将带您一步一步,图文并重,上手操作来学习它. 目录 一 Docker 下载镜像 1.1 下 ...

随机推荐

  1. .net 程序 动态 控制IIS 站点域名绑定

    第一步:引用 导入 System.EnterpriseServices及System.DirectoryServices 两个引用 程序引用: using System.DirectoryServic ...

  2. 测试那些事儿-Jmeter介绍及使用

    Jmeter与LR有啥区别? Jmeter工具组成部分: 1.资源生成器:用于生成测试过程中服务器,负载机的资源代码.(LR中的VuGen) 2.用户运行器:通常是一个脚本运行引擎,根据脚本要求模拟指 ...

  3. Go爬去以太坊的价格数据

    package main import ( "encoding/json" "errors" "fmt" "io/ioutil&q ...

  4. Python学习笔记–Chapter 2

    1.字符串中添加制表符,可使用字符组合\t 2.字符串中添加换行符,可使用字符组合\n 3.字符串\n\t可以换到下一行,并且在开头添加一个制表符. 4.删除末尾空白,使用方法rstrip() 5.删 ...

  5. 利用Python代码编写计算器小程序

    import tkinter import tkinter.messagebox import math class JSQ: def __init__(self): #创建主界面 self.root ...

  6. Android自定义标签列表控件LabelsView解析

    版权声明:本文为博主原创文章,未经博主允许不得转载. 无论是在移动端的App,还是在前端的网页,我们经常会看到下面这种标签的列表效果:   标签从左到右摆放,一行显示不下时自动换行.这样的效果用And ...

  7. 使用 whereis/which/locate 查找文件

    whereis命令 whereis只能用于搜索可执行文件 (-b) , 联机帮助文件 (-m) 和源代码文件 (-s) . 它只在一个数据库中查询(/var/lib/mlocate) . 这个数据库是 ...

  8. 序列化、time、random、hashlib、sys模块

    •很多常用和内置模块,我们只需要掌握他们的用法而暂时不用考虑内部是如何实现的,这些模块大大提升了开发效率 ! 1.json模块与pickle模块 •json 如果你有这样的困扰,当希望把一种数据存到硬 ...

  9. python 如何编写一个自己的包

    python 如何编写一个自己的包 先写function 内容 package/wadepypk$ ls __init__.py f1.py f2.py f1.py def show(): print ...

  10. zeebe 集成elasticsearch exporter

    zeebe 目前还在一直的开发中,同时一些变动还是挺大的,比如simple monitor 的以前是不需要配置HazelcastExporter的 估计是为了进行集群功能处理,新添加的,以前写的配置基 ...