Hi, I am rather new to Docker and managed to build a workaround for my app. For the front I’m using nodejs container, but I faced an issue as I had to make a second nodejs container with its own ports for sake of project migration. As I’ve run docker-compose up with the new container, my nginx, nodejs containers were unreachable by browser, though according to docker ps all of the containers were running and binded to 0.0.0.0:their_port.
I’ve tried to revert all changes I made but it didn’t work out. I also applied the docker system prune -a, though nothing has changed with the problem. I managed to make the nginx container work fine by renaming COMPOSE_PROJECT_NAME, but the nodejs container still responds with “the connection was reset”.
FROM node:16-alpine
ARG APP_PATH_HOST_FRONT
ARG APP_PATH_CONTAINER_FRONT
WORKDIR ${APP_PATH_CONTAINER_FRONT}
COPY ${APP_PATH_HOST_FRONT} ${APP_PATH_CONTAINER_FRONT}
RUN npm install
#EXPOSE 3000:3000
CMD npm run dev
I’m running on:
Docker Desktop v4.17.1
Docker: v20.10.23
Docker Compose: v2.15.1
Windows 10 Home, WSL2
That only shows the port forwards, not the port that the process inside the container is listening on. In your code you have two port definitions for nodejs but you haven’t mentioned which one you try to use. Probably port 3000 since this is the port in the comment in the Dockerfile… Is nodejs actually running properly inside the container and accessible from the inside on the port 3000? If it is listening only on that port on localhost, that will not be enough. It has to listen on 0.0.0.0 similar to what you see from the host in the output of docker ps.
What was your problem with nginx? How changing the project name helped? Was the old project name the same as another project?
Nodejs utilizes several ports, I just removed second(3001) to simplify testing. Nodejs is running and accessible though docker exec -it with all required content inisde.
Yes, nodejs is deployed primarily to localhost:3000. I unsure what you mean, I have to to define IP in the docker-compose file for the container?
It had same issue as nodejs container. I wasn’t able to reach it from the browser, even nginx default message on the root. As I’ve changed project name from “project” to “project1” it started to work as should.
I don’t know how it is done in case of NodeJS, but if npm run dev run sa process that listens only on localhost, you need to find out the right parameters of enrvironment variables to change that behavior.
If you want to know whethe the process is listening on localhost, you can use a debug container and run in the network namespace of the nodejs container so you can use netstat to list the ip addresses and ports that are used inside the container
docker run --rm --network container:project-nodejs-1 nicolaka/netshoot netstat -nat
I totally forgot to mention, I have Nuxt 2 deployed on 3000 port. Also, as I have met with this problem, I noticed that I couldn’t use syntax like(instead of pointing WORKDIR and COPY in Dockerfile):
That would return Tracker "idealTree" already exists Though such approach worked well before.
EDIT:
Thanks a lot for pointing out the problem. For some reason Nuxt 2 refused to work(though not sure why) with old config. As I’ve added to nuxt.config.js: