L
L
lssssssssssl2021-11-28 21:23:58
Docker
lssssssssssl, 2021-11-28 21:23:58

Accessing localhost from docker container?

I'm really bad at everything so just tell me what to write in docker-compose so that the container can access localhost:8080 on the machine itself

Thanks a lot!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Karabanov, 2021-11-28
@lsssssssssl

You will have to remove isolation from the network , otherwise you will not be able to access localhost on the host machine from the container.
Or, you can make the service on the host machine listen on all interfaces and access it from the container at the gateway address in the virtual network to which the container is connected.

L
lssssssssssl, 2021-11-28
@lsssssssssl

Add to docker-compose

extra_hosts:
      - "host.docker.internal:host-gateway"

In code, use to access localhost:8080host.docker.internal:8080

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question