I've created a docker container with ubuntu image. In that I've created a react app and when I try to run the app I could not see the app is running on localhost but in the terminal of container it says its running on the port. How can we connect a docker container with our localhost.
CodePudding user response:
If You have a docker file just pass the port to docker run with -p 3001:3000
If you have a docker compose set the port with:
ports: - 3001:3000
and run docker-compose up -d
Finally navigate to localhost:{Port}
CodePudding user response:
From official documentation : docker run -p 127.0.0.1:80:8080/tcp ubuntu bash
This binds port 8080 of the container to TCP port 80 on 127.0.0.1 of the host machine. You can also specify udp and sctp ports. The Docker User Guide explains in detail how to manipulate ports in Docker.
Then docker ps
and verify its running and ports are exposed.
Also check about your firewall, it may block ports.