3

My docker-compose.yml looks like this:

my_app:
  build: .
  net: host
  command: bin/server
  ports:
    - "3001:3001"

I start the service like this:

docker-compose up

And I can see that it is running:

my_app_1  | * Listening

But I can't figure out how to access it. None of these work:

localhost:3001
docker-machine:3001
127.0.0.1:3001
0.0.0.0:3001

How can I access my Docker service?

cilphex
  • 6,006
  • 6
  • 34
  • 44
  • Check these out. https://stackoverflow.com/questions/17157721/how-to-get-a-docker-containers-ip-address-from-the-host – Adam Nov 02 '17 at 22:00
  • @Adam Thanks, unfortunately the docs don't provide a solution. `docker ps` shows nothing in the `PORTS` column for my conainer. `docker ps ` shows empty strings for all `IPAddress` values. – cilphex Nov 02 '17 at 22:14
  • Did you try docker inspect? – Alessandro Hoss Nov 02 '17 at 22:28
  • 1
    Yes, sorry, that's actually what I meant. `docker inspect ` shows empty strings for all `IPAddress` values. – cilphex Nov 02 '17 at 22:53
  • Could you post the `Dockerfile`, `bin/server` and `docker-compose.yml`? Redact anything sensitive and unnecessary. The ports appear fine (you could actually leave it as "3001" as "3001:3001" is redundant if you get what I'm saying). What version of docker-compose file are you using? My thought is that maybe you aren't mapping the correct port (bin/server is actually running on 5000 for example). The `net: host` is unnecessary if all of your containers are on the same network which essentially means they look like they are on the same machine. – Adam Nov 03 '17 at 04:46
  • Honestly I'd bet the issue is with the `docker-compose.yml` file. If you could just post that in it's entirety that would be great. – Adam Nov 03 '17 at 04:50
  • which OS are you running? also what is bin/server? Can you post the code for your server, Are you listening using `127.0.0.1` in server or `0.0.0.0`? It is important to listen on `0.0.0.0` in your `bin/server` program – Tarun Lalwani Nov 03 '17 at 08:15
  • ^ This is also true. Forgot about this but had that issue w/ a Flask app for a long time. – Adam Nov 03 '17 at 23:17

1 Answers1

2

docker inspect container_name/hash | grep Address

Galym
  • 57
  • 10