Answer the question
In order to leave comments, you need to log in
Why doesn't nextjs app work when trying to deploy with docker swarm?
Good day.
Created an application on nextjs. Added Dockerfile and docker-compose.yml with settings for docker swarm. I build the image, upload to docker hub, then run `docker stack deploy -c docker-compose.yml docktestapp', go to localhost:3000 and get the error "This page isn't working. localhost didn't send any data. ERR_EMPTY_RESPONSE ".
At the same time, according to the logs from the container, nextjs was successfully assembled, launched and should be available on port 3000.
When starting docker normally via docker run -dp 3000:3000 docktestapp everything works fine, the content is displayed on port 3000.
Also, if I run an application on express.js according to the same scheme, then everything works fine.
Why is this happening and how do I get swarm to work with nextjs?
dockerfile:
FROM node:16-alpine
# Create app directory
WORKDIR /app
# Install app dependencies
COPY package*.json ./
RUN npm install
# Bundle app source
COPY . .
RUN npm run build
EXPOSE 3000
CMD [ "npm", "run", "start" ]
version: '3.7'
services:
app:
image: wwwansmer/docktestapp
ports:
- "3000:3000"
command: npm run start
deploy:
replicas: 4
update_config:
parallelism: 2
order: start-first
failure_action: rollback
delay: 10s
rollback_config:
parallelism: 0
order: stop-first
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 120s
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000 || exit 1"]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question