How to get docker generated ip port from docker-compose

201 Views Asked by At

docker networking seems not working, docker supposed to know the address and port when specifying the container name, or what am I missing?

Would it be possible to get the generated ip port like:

docker-compose.yml

command: nsqd 
         --auth-http-address='host:docker inspect -f '{{(index 
         (index .NetworkSettings.Ports "80/tcp") 0).HostPort}}' some-image'

tried changing the --auth-http-address='0.0.0.0:80' for local address Im running it locally.

docker-compose.yml

services:
  service1:
    image: image_name
    command: nsqd --auth-http-address='authenticator'
  authenticator:
    image: some_image
    command: some server.py
    ports: - "80"
    container_name: authenticator

Had error message

Error: failed auth against authenticator address authenticator: missing port in address

1

There are 1 best solutions below

0
asolanki On

The error says it is expecting port number too. Change the command in docker-compose.yml to

 services:
  service1:
    image: image_name
    command: nsqd --auth-http-address=authenticator:80