How can I temporarily expose an internal service in Docker or Docker Compose?

0
0
Asked By CuriousCat99 On

I find `kubectl port-forward` really helpful for accessing internal services in Kubernetes temporarily. I'm looking for a clean equivalent in Docker or Docker Compose that can achieve the same temporary exposure of an internal service. Any suggestions?

3 Answers

Answered By TechWhiz42 On

You don't really have a direct equivalent command in Docker like `kubectl port-forward`. However, you can run a separate Nginx container to act as a proxy for your existing container by using something like:

alias docker-proxy='docker run --rm -p 8080:80 nginx --network'

Then, just point it to the container ID you want to proxy. It's not as direct, but it works!

JollyExplorer83 -

Interesting! But is that an SSH tunnel? I was hoping for something simpler to just expose a port for accessing it through my local browser.

Answered By NerdyNinja21 On

Typically, any service running inside a Docker container should be accessible on the host directly. You can use `docker inspect` to find the container's IP address and just connect using the service's port. If you expose the port, it’ll be available on `127.0.0.1` by default, too.

Answered By DevGuru_88 On

To mimic `kubectl port-forward`, you can use `docker run --rm -it --network container: nicolaka/netshoot` to create a debug container in the same network namespace. This way, you can use curl or nc directly to localhost and the service you need without any port mappings.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.