Arjun-Phalguna
Arjun-Phalguna

Reputation: 19

How to Connect Docker Container to localhost

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.

Upvotes: 0

Views: 2740

Answers (2)

Sachith Muhandiram
Sachith Muhandiram

Reputation: 2972

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.

Upvotes: 0

jmvcollaborator
jmvcollaborator

Reputation: 2455

  • 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}

Upvotes: 1

Related Questions