目的:下载 docker images 之后,了解 images 内部目录、文件结构,以及容器内部程序运行情况
方法:
1. 使用docker exec
(最简单)
和nsenter
命令类似,docker exec
命令可以在已经运行的容器运行新的进程(容器必须已经运行才可以,否则会报错),可以运行/bin/bash
进入容器:
[arthur@localhost Downloads]$ sudo docker ps
[sudo] password for arthur:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
09b6673f175a hicstuff:v1.0 "/bin/bash" 2 hours ago Up 2 hours quizzical_chatelet
c67a7e98646a koszullab/hicstuff "/bin/bash" 4 hours ago Up 4 hours sleepy_bhabha
[arthur@localhost Downloads]$ sudo docker exec -it quizzical_chatelet /bin/bash
(base) root@09b6673f175a:/app# pwd
/app
(base) root@09b6673f175a:/app# ls
LICENSE __init__.py distance_law.py io.py pipeline.py test_commands.py test_filter.py tests
MANIFEST.in commands.py filter.py iteralign.py requirements.txt test_digest.py test_hicstuff.py version.py
Makefile cutsite.py hicstuff log.py setup.cfg test_distance_law.py test_io.py view.py
README.md digest.py hicstuff.py main.py setup.py test_doctests.py test_pipeline.py
2. 使用快照(snapshotting)
#查看已经运行的容器,记录要查看容器的 ID
$ docker ps
#创建新的 images
$ docker commit ID NewImagesName
#通过 `bash` 进入新镜像
$ docker run -it NewImagesName /bin/bash
#删除新的镜像 NewImagesName
$ docker rmi NewIamgesName
3. 使用 ssh
如果需要持续性连接到容器,可以在容器内安装sshd
,并运行sshd
#查看 容器 port
$ docker ps
#
$ docker run -d -p PortNumber ContainerName /usr/sbin/sshd -D
4. 使用nsenter
5. 覆盖默认的 ENTRYPOINT
$ docker run --rm -it --entrypoint=/bin/bash NameofImage
#########################################################################
--entrypoint string Overwrite the default ENTRYPOINT of the image
#覆盖默认 entrypoint
[arthur@localhost Downloads]$ sudo docker run --rm -it --entrypoint=/bin/bash koszullab/hicstuff
[sudo] password for arthur:
(base) root@1f60e1415681:/app# pwd
/app
(base) root@1f60e1415681:/app# ls
LICENSE __init__.py distance_law.py io.py pipeline.py test_commands.py test_filter.py tests
MANIFEST.in commands.py filter.py iteralign.py requirements.txt test_digest.py test_hicstuff.py version.py
Makefile cutsite.py hicstuff log.py setup.cfg test_distance_law.py test_io.py view.py
README.md digest.py hicstuff.py main.py setup.py test_doctests.py test_pipeline.py
(base) root@1f60e1415681:/app#
#未覆盖
[arthur@localhost Downloads]$ sudo docker run -it koszullab/hicstuff
[sudo] password for arthur:
INFO :: generated new fontManager
usage:
hicstuff [-hv] <command> [<args>...]
[arthur@localhost Downloads]$ sudo docker run -it koszullab/hicstuff /bin/bash
INFO :: generated new fontManager
Unknown command.
usage:
hicstuff [-hv] <command> [<args>...]
[arthur@localhost Downloads]$
#运行其他 images
[arthur@localhost Downloads]$ sudo docker run -it hicpro:homo.v1
root@5bf6508e2b7c:/# exit
exit
[arthur@localhost Downloads]$ sudo docker run -it nservant/hicpro:v3.01
root@fb00a89cb150:/# exit
exit
#原镜像运行 commit 之后的
[arthur@localhost Downloads]$
[arthur@localhost Downloads]$ sudo docker run -it hicstuff:v1.0
[sudo] password for arthur:
(base) root@4de5fd7f7bae:/app# pwd
/app
(base) root@4de5fd7f7bae:/app# ls
LICENSE __init__.py distance_law.py io.py pipeline.py test_commands.py test_filter.py tests
MANIFEST.in commands.py filter.py iteralign.py requirements.txt test_digest.py test_hicstuff.py version.py
Makefile cutsite.py hicstuff log.py setup.cfg test_distance_law.py test_io.py view.py
README.md digest.py hicstuff.py main.py setup.py test_doctests.py test_pipeline.py
拓展:
- 镜像构建 dockfile 存在差别:
koszullab/hicstuff 镜像为 from conda , nservant/hicpro from ubuntu
- 原镜像 koszullab/hicstuff commit 之后与原镜像的差别:登陆方式出现差别
Reference :
[1] exploring Docker container's file system.stack overflow.