docker进程没有在后台运行

时间:2017-05-30 16:18:41

标签: docker

我正在尝试创建一个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 个答案:

答案 0 :(得分:0)

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

由于docker ps -a显示所有容器:正在运行的容器和未运行的容器。

您的命令grep可以正常工作,然后退出,因此容器也会退出。

-d在这里没有任何区别,因为容器的使用时间非常短。但您仍然可以使用docker logs <container-id>

查看输出结果

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

docker run -it imagename bash

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

请记住docker run创建一个新容器,因此那里的更改只会在该容器中。图像是不可变的。