I have my private self-hosted docker image with nextjs inside. This image exposes 3000 port.
I tried to run this image via docker and docker swarm.
- Docker
docker run -p 3000:3000 path-to-my-image
Result:
docker ps
:
0.0.0.0: 3000->3000/tcp, ::: 3000->3000/tcp
ps
inside container:
PID USER TIME COMMAND
1 nextjs 0:00 next-router-wo
22 nextjs 0:01 next-render-worker-app
23 nextjs 0:01 next-render-worker-pages
51 nextjs 0:00 sh
57 nextjs 0:00 ps
netstat -tulp|grep 3000
inside container:
tcp 0 0 cf748210f6f3:3000 0.0.0.0:* LISTEN 1/next-router-wo
curl http://127.0.0.1:3000
outputs correct response. So all is fine.
- Docker swarm
stack.yaml
version: "3.7"
services:
app:
image: path-to-my-image
ports:
- 3000:3000
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]
docker service ls
shows service is online, 1 replica
ps
inside container:
PID USER TIME COMMAND
1 nextjs 0:00 next-router-wo
22 nextjs 0:01 next-render-worker-app
23 nextjs 0:01 next-render-worker-pages
50 nextjs 0:00 sh
56 nextjs 0:00 ps
netstat -tulp|grep 3000
inside container:
tcp 0 0 3e53ca570e77:3000 0.0.0.0:* LISTEN 1/next-router-wo
But curl http://127.0.0.1:3000
fails:
curl: (7) Failed to connect to 127.0.0.1 port 3000 after 0 ms: Connection refused
Tried another port, another machines, tried node
and pm2
. All is same.
I can’t understand the reason and where to dig next.
Thank you in advance.