I am novice on Docker, just started learning about it. As a first step, here is what I have done.
(1) On Windows 11, installed Virtual Box (v7.0.8)
(2) Started Virtual Box with Ubuntu OS (v22.04)
(3) Installed Docker
(4) Followed instructions, as given on Get Started => Part 2: Containerize an application, to create dockerfile
(5) Started container, $sudo docker run -dp 3000:5050 app-temp
(6) Opened Firebox and entered address (http://localhost:3000)
(7) Gets page showing error: The connection was reset. The connection to the server was reset while the page was loading
Additional info, there is no issue on Firefox, as I can open any other site like, https://docs.docker.com/, without any issue. Any help deeply appreciated
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
Is this the Dockerfile you used?
Can you share why your docker run command maps host port 3000 to container port 5050? Also, please share the code changes to the node project that it actually listens on port 5050.
Just changing EXPOSE 3000 to EXPOSE 5050 does not change on which port the node application works. It will still listen on port 3000, unless you specifically made code changes to the node project itself.
In dockerfile, I had exposed 5050, so while creating container, mapping was done as 3000:5050. As suggested, when it was changed to 3000 in the dockerfile, it worked.
So please help me further to understand why after changing port to 3000, it worked? Was port 5050 already in use by anyway causing the issue? If so, is there anyway to check where port is in use to avoid such issue.
It will even work if you remove the EXPOSE instruction.It is mainly a hint for documentation purposes, and used by some docker management UIs like Portainer or the Synology Docker UI. EXPOSE does nothing on its own.
As I already wrote: the application needs to be configured to actually listen on the port. So if the node application listens on port 3000, then it will be reachable at the container port 3000, regardless whether you declare it as EXPOSE or use a different port in the EXPOSE declaration.