我正在使用Ubuntu 22.04,并试图让这个nextjs示例工作:https://github.com/vercel/next.js/tree/canary/examples/with-docker-multi-env
我已经安装了Docker,并使用了以下指南:https://docs.docker.com/engine/install/ubuntu/
然后我执行了以下操作
npx create-next-app --example with-docker-multi-env nextjs-docker-multi-env
make build-development
make start-development
字符串
现在,当我尝试在Firefox中访问http://localhost:3001时,网站不显示(“连接已重置”)。docker ps
的输出:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1ffae309639e with-docker-multi-env-development "docker-entrypoint.s…" 21 minutes ago Up 21 minutes 0.0.0.0:3001->3000/tcp, :::3001->3000/tcp development-with-docker-multi-env-development-1
型
Docker镜像的输出:
[+] Building 0.0s (0/0)
[+] Running 1/0
✔ Container development-with-docker-multi-env-development-1 Created 0.0s
Attaching to development-with-docker-multi-env-development-1
development-with-docker-multi-env-development-1 | ▲ Next.js 14.0.3
development-with-docker-multi-env-development-1 | - Local: http://localhost:3000
development-with-docker-multi-env-development-1 | - Network: http://127.0.0.1:3000
development-with-docker-multi-env-development-1 |
development-with-docker-multi-env-development-1 | ✓ Ready in 55ms
型
其他的docker镜像,比如https://hub.docker.com/_/postgres,对我来说没有问题。
我是否需要采取其他步骤才能使其发挥作用?
1条答案
按热度按时间6yt4nkrj1#
我已经解决了。对于所有有同样问题的人:
您必须在
Dockerfile
中更改以下行:ENV HOSTNAME localhost
个到
ENV HOSTNAME "0.0.0.0"
个由于某种原因,它们在不同的
Dockerfile
(https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile)中有这条精确的线。