Solution for can't connect to docker container port of some images
The reason why you were able to connect to port 888 on the nginx container but not on the Ubuntu or Node.js containers is that the nginx container has a process running on that port, while the other containers don't.
When you run the nginx container with the command "docker run -p 888:888 -it nginx /bin/bash", you are telling Docker to map port 888 on the host to port 888 on the container, and start a bash shell in the container.
Inside the container, nginx is running as a process that is listening on port 888. When you connect to port 888 on the host, Docker forwards the traffic to port 888 in the container, where nginx is listening and responding.
In contrast, when you ran the Ubuntu or Node.js containers and tried to listen on port 888 with netcat, there was no process running on that port inside the container. Therefore, when you tried to connect to port 888 on the host, there was nothing to respond to the connection, and you got a "Connection refused" error.
If you want to run a process that listens on a port inside a Docker container, you need to make sure that the process is running inside the container and that the port is open. You can do this by installing and configuring the necessary software inside the container, or by using a pre-built image that already has the software you need installed.
Comments
Post a Comment