0
version: '3.7'
services:
  translate:
    restart: always
    # Docker file here: https://github.com/mashirozx/google-translate-server/blob/master/Dockerfile
    image: mashirozx/google-translate-server:latest
    ports:
      - "127.0.0.1:30031:30031"
    command: "npm start -- --domain ${DOMAIN:-cn}"
    networks:
      - external_network
      - internal_network

  app:
    image: app:dev
    networks:
      - external_network
      - internal_network
    depends_on:
      - translate
    links:
      - "translate:translationserver"

In app container, both hostname translate and translationserver is unable to resolve, and I tried to use the server public IP, http://public.IP:30031 is accessible in app. SO the problem is the hostname not resolved in app container.

Same question, but no one solve my problem:

docker-compose fails to resolve service hostname

How do I set hostname in docker-compose?

Mashiro
  • 1,032
  • 1
  • 12
  • 24

1 Answers1

1

links is deprecated, since you don't need it to access other contianers in the same docker-network.

https://docs.docker.com/compose/compose-file/#links

Try removing links and use in your app name translate: docker will resolve internal IP (docker vlan) to access it.

version: '3.7'
services:
  translate:
    restart: always
    # Docker file here: https://github.com/mashirozx/google-translate-server/blob/master/Dockerfile
    image: mashirozx/google-translate-server:latest
    container_name: translate
    ports:
      - "127.0.0.1:30031:30031"
    command: "npm start -- --domain ${DOMAIN:-cn}"
    networks:
      - external_network
      - internal_network

  app:
    image: app:dev
    container_name: myapp
    networks:
      - external_network
      - internal_network
    depends_on:
      - translate
Alejandro Galera
  • 3,445
  • 3
  • 24
  • 42