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.
Asked
Active
Viewed 1,140 times
0
-
1you have to expose the port as well as bind it when you do `docker run` – Daniel A. White Oct 09 '22 at 01:01
-
Have you [published the port](https://docs.docker.com/config/containers/container-networking/#published-ports)? – Nick ODell Oct 09 '22 at 01:01
-
@DanielA.White The docker run works for docker compose file. But I haven't created any compose file in my app directory. I just want to use the image in a way that we use in windows. can the app start directly and can we view in the local host? – Arjun-Phalguna Oct 09 '22 at 01:58
2 Answers
1
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}

jmvcollaborator
- 2,141
- 1
- 6
- 17
-
is there a way we can avoid docker compose? like we work on react apps in windows? what want to know is whether it is possible to run an application on the command line (nom start) and able to see it on the localhost – Arjun-Phalguna Oct 09 '22 at 02:00
0
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.

Sachith Muhandiram
- 2,819
- 10
- 45
- 94