探索Docker容器的文件系统 [英] Exploring Docker container's file system

查看:175
本文介绍了探索Docker容器的文件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经注意到docker,我需要了解一个容器内发生了什么,或者存在哪些文件。一个例子是从docker索引下载图像 - 您没有线索图像包含什么,因此无法启动应用程序。



最理想的是能够ssh到他们或等同的。有没有一个工具来做这个,或者我的概念化码头错误的想法我应该能够做到这一点。

解决方案

方法1:快照



您可以这样评估容器文件系统:

 #查找正在运行的容器的ID:
docker ps

#从容器文件系统创建映像(快照)
docker commit 12345678904b5 mysnapshot

#使用bash浏览此文件系统(例如)
docker运行-t -i mysnapshot / bin / bash

这样,您可以在精确的时间内评估正在运行的容器的文件系统。容器仍在运行,不包括将来的更改。



您可以稍后删除快照(运行容器的文件系统不受影响!):

  docker rmi mysnapshot 

方法2:ssh



如果需要持续访问,可以将sshd安装到容器并运行sshd守护程序:

  docker run -d -p 22 mysnapshot / usr / sbin / sshd -D 

#你需要找出哪个要连接的端口:
docker ps

这样,您可以使用ssh连接并执行你想要的。)



更新 - 方法3:nsenter



使用 nsenter ,请参阅 http://blog.docker.com/2014/06/why-you-dont-need-to-run-sshd-in-docker/


简短版本是:with nse nter,你可以得到一个shell
现有的容器,即使该容器不运行SSH或任何类型
的专用守护程序


更新 - 方法4:docker exec



Docker版本1.3(最新的,你可能需要使用docker apt repo来安装2014年11月的最新版本)支持新命令 exec ,其行为类似于 nsenter 。此命令可以在已运行的容器中运行新进程(容器必须已经有PID 1进程运行)。您可以运行 / bin / bash 来探索容器状态:

  docker exec -t -i mycontainer / bin / bash 

请参阅 Docker命令行文档


I've noticed with docker that I need to understand what's happening inside a container or what files exist in there. One example is downloading images from the docker index - you don't have a clue what the image contains so it's impossible to start the application.

What would be ideal is to be able to ssh into them or equivalent. Is there a tool to do this, or is my conceptualisation of docker wrong in thinking I should be able to do this.

解决方案

Method 1: snapshoting

You can evaluate container filesystem this way:

# find ID of your running container:
docker ps

# create image (snapshot) from container filesystem
docker commit 12345678904b5 mysnapshot

# explore this filesystem using bash (for example)
docker run -t -i mysnapshot /bin/bash

This way, you can evaluate filesystem of the running container in the precise time moment. Container is still running, no future changes are included.

You can later delete snapshot using (filesystem of the running container is not affected!):

docker rmi mysnapshot

Method 2: ssh

If you need continuous access, you can install sshd to your container and run the sshd daemon:

 docker run -d -p 22 mysnapshot /usr/sbin/sshd -D

 # you need to find out which port to connect:
 docker ps

This way, you can run your app using ssh (connect and execute what you want).

UPDATE - Method 3: nsenter

Use nsenter, see http://blog.docker.com/2014/06/why-you-dont-need-to-run-sshd-in-docker/

The short version is: with nsenter, you can get a shell into an existing container, even if that container doesn’t run SSH or any kind of special-purpose daemon

UPDATE - Method 4: docker exec

Docker version 1.3 (latest, you might need to use docker apt repo to install latest version as of Nov 2014) supports new command exec that behave similar to nsenter. This command can run new process in already running container (container must have PID 1 process running already). You can run /bin/bash to explore container state:

docker exec -t -i mycontainer /bin/bash

see Docker command line documentation

这篇关于探索Docker容器的文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆