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 下 ...
随机推荐
- celery使用rabbitmq报错[Errno 104] Connection reset by peer.
写好celery任务文件,使用celery -A app worker --loglevel=info启动时,报告如下错误: [2019-01-29 01:19:26,680: ERROR/MainP ...
- 小程序cover-view踩过的坑
1.前段时间开发一个小程序,里边用到cover-view,发现cover-view其实很多都是不支持的,比如动画,如果你想要在cover-view上边加动画你会发现没有效果,虽然在模拟器里边可以显示动 ...
- Centos下查看当前目录大小及文件个数
查看目录及其包含的文件的大小 du -ch directory 查看当前目录下文件的个数 ls -l | grep "^-" | wc -l 查看当前目录下以.jpg为后缀文件的个 ...
- div介绍 盒子模型边框属性 CSS初始化 文字排版 边框调整 溢出
今天学习的div,了解了div是干什么用的掌握了什么是盒子模型,以及div的外边距内边距以及边框,运用div和CSS给文字排版,利用边框的来做图像,div溢出的处理 CSS初始化: 精确排版的时候用这 ...
- 请用java解析下xml
Java XML简介 XML(EXtensible Markup Language) 可扩展标记语言 可以说是一个文本文件 作用数交互 配置应用程序 Xml解析技术 三种方式 Dom 文档数据 ...
- maven无法下载oracle驱动包
由于版权问题,在中央仓库是没有oracle的jdbc驱动的,可以手动下载到本地或者在oracle安装目录的jdbc目录中找到对应的jar,然后通过以下命令安装到本地仓库 mvn install:ins ...
- GraphQL搭配MongoDB入门项目实战
什么是GraphQL GraphQL 是一种面向 API 的查询语言.在互联网早期,需求都以 Web 为主,那时候数据和业务需求都不复杂,所以用 RestAPI 的方式完全可以满足需求.但是随着互联网 ...
- C#中使用EntityFramework(EF)生成实体进行存储过程的调用
在EF中使用定义对象模型的方式调用一个存储过程,这个存储过程返回的是一组包含两列的值.(ProjectName,Count) 下面是存储过程: CREATE procedure [dbo].[Pro_ ...
- jquery: 获取当前天加减一天
// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...
- libvirt启动报错Failed to start Virtualization daemon
libvirt启动报错Failed to start Virtualization daemon 1.启动libvirt的具体报错如下 [root@localhost IOS]# service li ...