Docker - 安装了主机卷的 nginx 使用 docker-compose 挂起

Docker - nginx with mounted host volume hangs using docker-compose

我是 Docker 的新手,我在设置简单的文件服务器时遇到了问题。我的目标是 link 主机卷 (Windows) 到来宾 Linux VM。

问题是在 运行 docker-compose up 之后,控制台挂起并显示标准输出 "Attaching to docker_web_1"。

我有三个主要文件和一个文件夹,这是服务器 "web" 的根目录,我需要附加到 Linux VM。

docker-compose.yml:

web:
  image: nginx
  volumes:
   - C:/docker/web:/usr/share/nginx/html/
  ports:
   - "8080:80"

Docker文件:

FROM nginx:latest
COPY nginx.conf /etc/nginx/nginx.conf`

nginx.conf:

worker_processes 1;

events { worker_connections 1024; }

http {
    sendfile on;
    server {
        root /usr/share/nginx/html/;
        index index.html;
        server_name localhost;
        listen 80;
    }
}

谁能帮我设置这个服务器?

这是预期的,附加意味着您的控制台 'linked' 带有容器的 stdout 和 stderr。

如果您访问 localhost:8080,您应该能够在您的控制台中看到日志。

如果您不想要日志,请使用 docker-compose up -d-d 表示 detached