"This site can't be reached" but container seems to work fine

Hi guys. I’m new to this community and to docker. I’ve started learning this wonderful platform one week ago, learning the basics (containers, images, how to build, some commands etc).

I was following this guide: The Docker Handbook – Learn Docker for Beginners and tried to build an image for a frontend project with react and tailwind with vite (just for learn how to do it). After some tries and change some commands i was able to build an image and start a container from that image but when i try to connect from local in chrome i receive an error: “This site can’t be reached, The connection was reset.”

This is the dockerfile:

FROM node:lts

EXPOSE 3000
# Set the working directory
WORKDIR /home/node/app
# Copy package files and install dependencies
COPY package.json ./
COPY package-lock.json ./
RUN npm install

# Copy the rest of the application code
COPY . .

# Adjust permissions
RUN chown -R node:node /home/node/app
RUN chmod -R u+w /home/node/app

# Switch to non-root user
USER node
CMD ["npm", "run", "dev"]

this is the command that i used to build the image:

docker image build --file ./Dockerfile --tag cassone16:dev .

and this is the command used for start the image and create the container

docker run -d -p 3000:3000 cassone16:dev 

I running docker from a mac
I just want clear out that the guide i used do not mention yaml file.

from the title: “but container seems to work fine”

How do you know that?

Which meanc what exactly? What IP or hostname? (and port)

i think it’s working fine because i don’t have any errors and docker says it is up and running.

I mean, following that guide, in the browser, tried to connect to “127.0.0.1:3000” but chrome said “the connection was reset”

Where did you look for the error messages? The guide also shows how you can check the error messages in the container. Connection reset means the port was open, but the application didn’t listen on that port.

1 Like

On terminal i used logs command. (docker logs “container_id”)

This is the result:

0 verbose cli /usr/local/bin/node /usr/local/bin/npm
1 info using npm@10.8.1
2 info using node@v20.14.0
3 silly config load:file:/usr/local/lib/node_modules/npm/npmrc
4 silly config load:file:/home/node/app/.npmrc
5 silly config load:file:/home/node/.npmrc
6 silly config load:file:/usr/local/etc/npmrc
7 verbose title npm run dev
8 verbose argv "run" "dev"
9 verbose logfile logs-max:10 dir:/home/node/.npm/_logs/2024-06-23T09_17_40_405Z-
10 verbose logfile /home/node/.npm/_logs/2024-06-23T09_17_40_405Z-debug-0.log
11 silly logfile done cleaning log files
12 http fetch GET 200 https://registry.npmjs.org/npm 609ms

solved. Through this command "docker exec -it “container_id” /bin/sh and then curl http://localhost:3000, like you said i verified that the application wasn’t listening on the 3000 port. I solved this by edit vite.config file, by adding some configuration.

thank you for the help :). Really appreciated

1 Like