“Docker 容器运行”不再返回生成的容器 ID,而是返回其日志

时间:2021-05-04 21:14:46

标签: docker

我是新手,正在做 docker 实验。

一次,当我跑步时

docker container run --publish 80:80 nginx

我刚刚得到了生成的容器 ID。

然后我做了各种事情,现在,当我运行相同的命令时,我得到

$ docker container run --publish 80:80 nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up

为什么?这是因为我现在在具有 Dockerfile 的不同目录中运行相同的命令吗?

这里是Dockerfile的内容:

# this shows how we can extend/change an existing official image from Docker Hub

FROM nginx:latest
# highly recommend you always pin versions for anything beyond dev/learn

WORKDIR /usr/share/nginx/html
# change working directory to root of nginx webhost
# using WORKDIR is preferred to using 'RUN cd /some/path'

COPY index.html index.html

# I don't have to specify EXPOSE or CMD because they're in my FROM

1 个答案:

答案 0 :(得分:1)

这取决于你如何启动 docker 容器。 您使用的命令会将其作为前台进程运行,并将容器的标准输出打印到控制台(Docker 默认)。

如果您只想查看 ID 并将其作为后台运行,则必须添加分离选项:

docker container run --detach --publish 80:80 nginx
docker run -d -p 80:80 nginx

https://docs.docker.com/engine/reference/run/#detached-vs-foregroundhttps://docs.docker.com/engine/reference/commandline/container_run/