天天看點

執行個體 : 檢視Docker容器内檔案系統

目的:下載下傳 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
           

拓展:

  1. 鏡像建構 dockfile 存在差别:

    koszullab/hicstuff 鏡像為 from conda , nservant/hicpro from ubuntu

  2. 原鏡像 koszullab/hicstuff commit 之後與原鏡像的差别:登陸方式出現差别

Reference :

[1] exploring Docker container's file system.stack overflow.