I’m facing a peculiar issue while Dockerizing my Node.js app on a Linux VPS, and I could really use some help figuring this out. Here’s the problem:
Problem Description:
I have a Node.js application that I’m trying to containerize using Docker on my Linux VPS. Here’s a simplified version of my Dockerfile:
dockerfile
Copy code
FROM node:18
COPY package.json .
RUN npm install
COPY . .
EXPOSE 80
CMD [ "node", "app.js" ]
Issue Encountered:
When I run my Docker container with port mapping -p 3000:80, everything works perfectly fine. I can access my app via hostname:3000 and external port checking tools like yougetsignal confirm that port 3000 is open.
However, when I try to use a different port, for example -p 3001:80, the container starts but external port checking tools indicate that port 3001 is closed. Accessing hostname:3001 also fails.
Steps Taken:
Docker Run Command: docker run -d –name node-app -p 3001:80 node-image
Verification: Checked port status using yougetsignal and attempted access via hostname:3001.
Expected Outcome:
I expect that by changing the port in the -p flag (-p 3001:80), I should be able to access my app via hostname:3001 and that port 3001 should show as open on external tools.
Additional Information:
The Linux VPS is running Ubuntu 22.04 – Jammy Jellyfish.
Conclusion:
I’m perplexed as to why only port 3000 seems to work. Is there something I’m missing in my Docker configuration or a step I need to take to allow Docker to map ports other than 3000 correctly?
also i try sudo ufw allow 3001
Any insights or suggestions would be greatly appreciated!