我使用 nginx 并打包了简单的配置:
server {
listen 80;
server_name my-address.com;
location / {
proxy_pass http://frontend:3000;
}
location /api {
proxy_pass http://localhost:8080;
rewrite ^/api/(.*) /$1 break;
}
}
我也使用 docker-compose 并用它配置 nginx:
nginx-server:
image: nginx:stable-alpine
container_name: nginx
ports:
- "80:80"
volumes:
- ./nginx/nginx.conf.prod:/etc/nginx/conf.d/nginx.conf
command: service nginx start
tty: true
depends_on:
- front
我添加到 /etc/hosts 127.0.0.1 my-address.com
在 docker-compose up 上 docker 构建 nginx 镜像并退出
nginx exited with code 127
我做错了什么?
答案 0 :(得分:1)
它以代码 127 退出,因为没有名为 service
的命令。如果您运行附加到您的 shell 的 docker-compose,(没有 -d
选项)您可以看到输出:
$ docker-compose up
Recreating nginx ... done
Attaching to nginx
nginx | /docker-entrypoint.sh: exec: line 38: service: not found
nginx exited with code 127
您应该删除该行
command: service nginx start
从您的 docker-compose 文件中,并使用图像中已有的默认命令。