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 下 ...
随机推荐
- 浅析toString()和toLocaleString()的区别
翻看<javascript高级程序设计>,对toString()和toLocaleString()两者的区别并没有直白的说明,简单查阅了一下 ecmascript官方文档 和 MDN 二者 ...
- Mesh内存分配器的mmap小技巧
最近看了一篇内存分配器的论文,原理很简单,但是里面的数学论证还没看懂,这次先简单写一下原理和用到的API. 内存分配器是用于封装操作系统提供的底层API,给应用程序提供动态内存的.内存不断申请释放后, ...
- MySQL 报错 1093
[Err] 1093 - You can't specify target table 'user' for update in FROM clause 报错的sql如下: delete from ` ...
- Python学习笔记,day2
Python学习第二天 一.模块 使用模块前需在代码最前声明(import) 二.数据类型 1.数字 int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2 ...
- 《python for data analysis》第八章,绘图与可视化
<利用python进行数据分析>一书的第8章,关于matplotlib库的使用,各小节的代码. # -*- coding:utf-8 -*-import numpy as npimport ...
- car的旅行路线
https://www.luogu.org/problemnew/show/P1027 题目描述 又到暑假了,住在城市A的Car想和朋友一起去城市B旅游.她知道每个城市都有四个飞机场,分别位于一个矩形 ...
- Mybatis逆向工程的配置
源码github下载地址:https://github.com/wcyong/mybatisGeneratorCustom.git 参考文章:https://www.cnblogs.com/whgk/ ...
- day-13装饰器
函数的嵌套定义 概念:在一个函数的内部定义另一个函数 为什么要有函数的嵌套定义:1)函数fn2想直接使用fn1函数的局部变量,可以将fn2直接定义到fn1的内部,这样fn2就可以直接访问fn1的变量2 ...
- Django学习笔记之上下文处理器和中间件
上下文处理器 上下文处理器是可以返回一些数据,在全局模板中都可以使用.比如登录后的用户信息,在很多页面中都需要使用,那么我们可以放在上下文处理器中,就没有必要在每个视图函数中都返回这个对象. 在set ...
- Beyond Compare 3添加右键菜单
目前是在Beyond Compare 3.1.9版本上试验可行,其他版本上尚未测试. 添加右键菜单步骤: 1.新建为.bat后缀的文本,将下面“添加右键菜单批处理”复制到此文本中. 2.将批处理移动到 ...