[Docker] Accessing a Container
If you want to get into container and look around, you can use:
docker container exec
to run against a running container. And to do that, we need to know the id / name of the running container.
To get id / name of the container, we can do:
docker container ls
For example, the name of the container is called: elegant_noether.
docker container exec elegant_noether du -mh
And 'du -mh' will print out the size of each folder:
$ docker container exec elegant_noether du -mh
16K ./error/include
220K ./error
44K ./build
.0K ./htdocs
892K ./include
72K ./conf/extra
72K ./conf/original/extra
96K ./conf/original
268K ./conf
260K ./icons/small
1.3M ./icons
20K ./cgi-bin
4.5M ./modules
.0K ./logs
1.2M ./bin
8.4M .
Running commands is cool, but we can also attach a shell to those containers and browse them just like they were a full operating system.
The -i
and -t
flags can be passed to the exec
command to keep an interactive shell open, and you can specify the shell you want to attach after the container ID. Here we'll attach a standard Bash shell.
docket container exec -it elegant_noether /bin/bash
We're in! From the perspective of the terminal window we're just navigating a normal Unix system, so any commands we type will run inside of that system. Try typing that same command we just ran with exec
from inside the container.
Now to check the size of each folder, we can just do:
du -mh
$ docker container exec -it elegant_noether /bin/bash
root@a8c267869b0b:/usr/local/apache2# du -mh
16K ./error/include
220K ./error
44K ./build
.0K ./htdocs
892K ./include
72K ./conf/extra
72K ./conf/original/extra
96K ./conf/original
268K ./conf
260K ./icons/small
1.3M ./icons
20K ./cgi-bin
4.5M ./modules
.0K ./logs
1.2M ./bin
8.4M .
Another thing we can do once we’re in a container’s shell is install new programs, or packages, that aren’t part of the base image. Let’s install the fortunes
package.
apt-get install -y fortunes
The package was installed in
/usr/games/fortune
It’s kind of annoying to have to type /usr/games/
before the fortune
command, so let’s update the PATH
environment variable in the container so that we don’t have to type all of that anymore.
PATH=$PATH:/usr/games/
Now we can export path:
export PATH
After that we can just type 'fortune' to start the game
[Docker] Accessing a Container的更多相关文章
- docker的网络-Container network interface(CNI)与Container network model(CNM)
Overview 目前围绕着docker的网络,目前有两种比较主流的声音,docker主导的Container network model(CNM)和社区主导的Container network in ...
- Docker入门03——Container
1 启动容器 1.1 新建并启动 1.2 启动已终止容器 2 后台运行 3 终止 4 进入容器 5 导入和导出 5.1 导出 5.2 导入 6 删除 1 启动容器 1.1 新建并启动 docker r ...
- docker Cannot start container [8] System error: exec format error
docker Cannot start container [8] System error: exec format error 学习了:https://www.aliyun.com/jiaoch ...
- Docker 容器(container)
版权所有,未经许可,禁止转载 章节 Docker 介绍 Docker 和虚拟机的区别 Docker 安装 Docker Hub Docker 镜像(image) Docker 容器(container ...
- Docker实现退出container后保持继续运行的解决办法
现象: 运行一个image,例如ubuntu14.04: 1 docker run -it --rm ubuntu:14.04 bash 退出时: 执行Ctrl+D或者执行exit 查看线程: 1 d ...
- Redis in Docker on Linux Container
记录:在Docker中运行一个Redis实例当我们在Windows系统中安装好Docker以后,在Hyper-V中会自动创建一个Linux虚拟机,如果这个虚拟机没有运行,说明当前运行的是Windows ...
- centos rancher 通过本机 docker images 新增container
示例目标: 将centos 本地的docker image ,通过rancher 进行 add container 相关步骤: step 1 : rancher 所在 centos 主机,有相应的 d ...
- Docker之删除container和image
删除所有停止的container: docker rm $(docker ps -a -q) 删除所有未标记的image docker rmi $(docker images | grep " ...
- Docker - 避免启动container后运行shell脚本执行完成后docker退出container
问题 最近在使用 Dockerfile 启动容器,发现使用Dockerfile调用容器里面的shell,当shell执行完成以后,docker会退出容器. 分析 Docker 在执行shell的时候, ...
随机推荐
- 11.使用 package.json
转自:http://www.runoob.com/nodejs/nodejs-express-framework.html package.json 位于模块的目录下,用于定义包的属性.接下来让我们来 ...
- Five ways to maximize Java NIO and NIO.2--转
原文地址:http://www.javaworld.com/article/2078654/java-se/java-se-five-ways-to-maximize-java-nio-and-nio ...
- 数组&对象
一.遍历数组的几种方式 var arr = [1,2,3]; Array.prototype.test=function(){} arr.name='jq' 1. for /* * inde ...
- jsp中标签id和name的区别(转)
name原来是为了标识之用,但是现在根据规范,都建议用id来标识元素. 但是name在以下用途是不能替代的:1. 表单(form)的控件名,提交的数据都用控件的name而不是id来控制.因为有许多na ...
- 关于java中String的一点理解
String类是java的最基本类之中的一个,非常好的掌握它的原理非常是必要的! 1.String的Final类型的.是不可继承 的.final类默认的方法都为final类型,保证了方法不能被 ...
- [React] Render Text Only Components in React 16
In this session we create a comment component to explore how to create components that only render t ...
- ontouch、dispatchtouchevent、interceptouchevent-相关事件
这几天一直在研究onTouch的相关方法,今天我们就来看看onTouchEvent.dispatchTouchEvent.onIntercepTouchEvent这三个方法在控件之间的传递顺序 pub ...
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第三篇:ASP.NET MVC全局观
摘要 本文对ASP.NET MVC的全局运行机理进行一个简要的介绍,以使得朋友们更好的理解后续文章. 前言 在上一篇文章中,我们实现了第一个ASP.NET MVC页面.对于没有接触 ...
- Oracle调用Java类开发的存储过程、函数的方法
oracle调用java类的基本步骤 1. 编写java代码,后续可以直接使用java代码,class文件或者jar包 2. 将写好的java代码导入到oracle数据库中,有两种方法:一种是使用lo ...
- 新版本的AutoCAD2018 怎样删除 A360 Drive盘符
通常的做法,如下: (1)点击开始菜单的“运行”(Win+R或者Win+X快捷选择运行),在弹出的对话框输入“regedit”,回车,进入注册表编辑器. (2)找到HKEY_LOCAL_MACHINE ...