2017-05-30 61 views
1

我試圖創建一個ubuntu docker鏡像,但是當我檢查進程時進程沒有在後臺運行。碼頭過程沒有在後臺運行

下面是命令

PREMs-MacBook-Pro:Documents prem$ docker run ubuntu:16.04 grep -v '^#' /etc/apt/sources.list 
deb http://archive.ubuntu.com/ubuntu/ xenial main restricted 

deb http://archive.ubuntu.com/ubuntu/ xenial-updates main restricted 

deb http://archive.ubuntu.com/ubuntu/ xenial universe 
deb-src http://archive.ubuntu.com/ubuntu/ xenial universe 
deb http://archive.ubuntu.com/ubuntu/ xenial-updates universe 
deb-src http://archive.ubuntu.com/ubuntu/ xenial-updates universe 

deb http://archive.ubuntu.com/ubuntu/ xenial multiverse 
deb http://archive.ubuntu.com/ubuntu/ xenial-updates multiverse 

deb http://archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse 


deb http://security.ubuntu.com/ubuntu/ xenial-security main restricted 
deb http://security.ubuntu.com/ubuntu/ xenial-security universe 
deb-src http://security.ubuntu.com/ubuntu/ xenial-security universe 
deb http://security.ubuntu.com/ubuntu/ xenial-security multiverse 
PREMs-MacBook-Pro:Documents prem$ docker run ubuntu:16.04 grep -v '^#' /etc/apt/sources.list 
deb http://archive.ubuntu.com/ubuntu/ xenial main restricted 

deb http://archive.ubuntu.com/ubuntu/ xenial-updates main restricted 

deb http://archive.ubuntu.com/ubuntu/ xenial universe 
deb-src http://archive.ubuntu.com/ubuntu/ xenial universe 
deb http://archive.ubuntu.com/ubuntu/ xenial-updates universe 
deb-src http://archive.ubuntu.com/ubuntu/ xenial-updates universe 

deb http://archive.ubuntu.com/ubuntu/ xenial multiverse 
deb http://archive.ubuntu.com/ubuntu/ xenial-updates multiverse 

deb http://archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse 


deb http://security.ubuntu.com/ubuntu/ xenial-security main restricted 
deb http://security.ubuntu.com/ubuntu/ xenial-security universe 
deb-src http://security.ubuntu.com/ubuntu/ xenial-security universe 
deb http://security.ubuntu.com/ubuntu/ xenial-security multiverse 
PREMs-MacBook-Pro:Documents prem$ docker ps 
CONTAINER ID  IMAGE    COMMAND    CREATED    STATUS    PORTS    NAMES 
+1

爲什麼你認爲'docker run ubuntu:16.04 grep ...'會在後臺運行,尤其是考慮到它會在你面前打印輸出? – jwodder

+0

當我做一個docker ps時,它沒有列出'container id'..當我添加ps -a時,它列出了所有的進程。在你的問題背景中,我沒有包含-d命令。 – user1050619

+0

所以你知道'-d'會在後臺運行Docker容器。你有什麼問題? – jwodder

回答

0

簡單的答案是,當您檢查運行容器(docker ps

由於docker ps -a您的容器已經退出顯示出所有的容器:那些運行和不運行。

您的命令grep會執行此操作,然後退出,因此容器也會退出。

-d這裏沒有什麼區別,因爲容器的壽命很短。但你仍然可以看到它的使用docker logs <container-id>


如果你想檢查的圖像輸出,只是爲了好玩,你可以:

docker run -it imagename bash 

(使用sh如果bash不可用)

熊記住docker run創建一個新的容器,所以更改將只在該容器中。圖像是不可變的。