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的更多相关文章

  1. docker的网络-Container network interface(CNI)与Container network model(CNM)

    Overview 目前围绕着docker的网络,目前有两种比较主流的声音,docker主导的Container network model(CNM)和社区主导的Container network in ...

  2. Docker入门03——Container

    1 启动容器 1.1 新建并启动 1.2 启动已终止容器 2 后台运行 3 终止 4 进入容器 5 导入和导出 5.1 导出 5.2 导入 6 删除 1 启动容器 1.1 新建并启动 docker r ...

  3. 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 ...

  4. Docker 容器(container)

    版权所有,未经许可,禁止转载 章节 Docker 介绍 Docker 和虚拟机的区别 Docker 安装 Docker Hub Docker 镜像(image) Docker 容器(container ...

  5. Docker实现退出container后保持继续运行的解决办法

    现象: 运行一个image,例如ubuntu14.04: 1 docker run -it --rm ubuntu:14.04 bash 退出时: 执行Ctrl+D或者执行exit 查看线程: 1 d ...

  6. Redis in Docker on Linux Container

    记录:在Docker中运行一个Redis实例当我们在Windows系统中安装好Docker以后,在Hyper-V中会自动创建一个Linux虚拟机,如果这个虚拟机没有运行,说明当前运行的是Windows ...

  7. centos rancher 通过本机 docker images 新增container

    示例目标: 将centos 本地的docker image ,通过rancher 进行 add container 相关步骤: step 1 : rancher 所在 centos 主机,有相应的 d ...

  8. Docker之删除container和image

    删除所有停止的container: docker rm $(docker ps -a -q) 删除所有未标记的image docker rmi $(docker images | grep " ...

  9. Docker - 避免启动container后运行shell脚本执行完成后docker退出container

    问题 最近在使用 Dockerfile 启动容器,发现使用Dockerfile调用容器里面的shell,当shell执行完成以后,docker会退出容器. 分析 Docker 在执行shell的时候, ...

随机推荐

  1. numpy_basic3

    矩陣 矩阵是numpy.matrix类类型的对象,该类继承自numpy.ndarray,任何针对多维数组的操作,对矩阵同样有效,但是作为子类矩阵又结合其自身的特点,做了必要的扩充,比如:乘法计算.求逆 ...

  2. HTML的SEO(搜索引擎优化)标准

    HTML的SEO(搜索引擎优化)标准 一.总结 这个做seo的时候要多看,做网站优化的时候 1. SEO(搜索引擎优化):通过总结搜索引擎的排名规律,对网站进行合理优化,使你的网站在百度和Google ...

  3. LayUI-Table表格渲染

    记项目中又一表格使用方法,项目首选是使用BootstrapTable的,但是经过多番查证与调试,始终没有把固定列的功能调试成功,找到的成功的例子原样照搬都不行,文件引入也都没有问题,实在搞不懂了,如果 ...

  4. 洛谷 P2790 ccj与zrz之积木问题

    P2790 ccj与zrz之积木问题 题目背景 ccj和zrz无聊到了玩起了搭积木...(本题选自uva101,翻译来自<算法竞赛入门经典2>) 题目描述 从左到右有n个木块,编号从0到n ...

  5. 微信支付v2开发(7) 告警通知

    本文介绍微信支付中如何获得告警通知. 一.告警通知 为了及时通知商户异常,提高商户在微信平台的服务质量.微信后台会向商户推送告警通知,包括发货延迟.调用失败.通知失败等情况,通知的地址是商户在申请支付 ...

  6. (转)Oracle RAC日常管理命令

    转自:http://www.xuebuyuan.com/1206937.html 一.查看RAC环境 RAC架构,2节点信息 节点1 SQL> show parameter instance N ...

  7. VMWare中装Linux系统常见问题

    1.安装VMWare的时候,可能会提示vtx-m没开启 解决办法:重启笔记本电脑,按完开机键后,按住del或者F1或者F2,进入BIOS,在BIOS中找到intel-cietue开关,开启就 可以(如 ...

  8. 如何把传统写法改成框架形式 es6

    每天思考的问题: 1.什么是组件 2.什么是插件 3.如何把传统写法改成框架形式 4.前端为什么要使用框架,使用框架的好处是什么? Image.png http://www.zhihu.com/que ...

  9. TF卡电压 SD卡引脚

    //////////////////////////////////////////////////////////////////////////////////////////////////// ...

  10. 前端js常用正则表达式实例讲解

    本文内容整理自他人优秀的博客,非纯原创.仅借此学习和整理. 1.匹配用户名 规则描述: 长度4-6位: {4,16} 字母: [a-z] [A-Z] 数字: [0-9] 下划线: [_] 减号: [- ...