无法访问nextjs docker示例镜像

qgzx9mmu  于 2023-11-18  发布在  Docker
关注(0)|答案(1)|浏览(162)

我正在使用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,对我来说没有问题。
我是否需要采取其他步骤才能使其发挥作用?

6yt4nkrj

6yt4nkrj1#

我已经解决了。对于所有有同样问题的人:
您必须在Dockerfile中更改以下行:
ENV HOSTNAME localhost

ENV HOSTNAME "0.0.0.0"
由于某种原因,它们在不同的Dockerfilehttps://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile)中有这条精确的线。

相关问题