docer-compose.yml
# nginx
nginx_test:
container_name: "nginx_test"
image: "nginx"
tty: true
# command: nginx
command: nginx -g "daemon off;"
如果按照注释的地方配置,容器会一直是exited状态。
docker-compose 日志:
nginx_test exited with code 1
补充说明:
1 下载的官方镜像。
2 用docker inspect命令可以看到,默认的命令就是command: nginx -g "daemon off;",因此可以不填写 command配置。
但是我的问题是,为什么一定要加上daemon off, nginx 容器才能正常运行?
你下载的是否是官方镜像?
如果是官方镜像,不需要使用command,容器启动成功既nginx启动成功。