docker工程不在后台运行

我试图创build一个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 

简单的答案是你的容器已经退出,当你检查正在运行的容器( docker ps

作为docker ps -a显示所有的容器:那些运行和那些不运行。

你的命令grep工作,然后退出,所以容器也退出。

-d在这里没有什么区别,因为集装箱的生命期很短。 但是你仍然可以使用docker logs <container-id>看到它的输出


如果你想检查一个图像,只是为了好玩,你可以:

 docker run -it imagename bash 

(如果bash不可用,请使用sh

请记住, docker run创build一个新的容器,所以更改将只在该容器中。 图像是不可变的。