0

The cis container is running a simple flask server that calls daemon() on the backend. As part of the nested container's functionality, it needs to be able to access the git container as well as other infrastructure on the network.

In the current setup, all services are accessible to each other by hostname, and they are accessible to the other machines on the network, also by hostname. However, the nested container is unable to resolve hostnames.

What can I do so that the nested container is able to resolve the necessary hostnames?

def daemon(dc:DockerClient,
           url:str, image:str)->Tuple[str,int]:
    try:
        cont = dc.containers.create(image,
                                    #network='myproject_default',
                                    network='ops')
        try:
            cont.start()
            status = cont.wait()['StatusCode']
            logs = cont.logs().decode('utf-8')
            return logs, status
        finally:
            cont.remove()        
    except errors.APIError:
        raise
    except Exception:
        raise

Sample docker-compose config:

version: '3.8'
services:
  git:
    image: rockstorm/git-server
    hostname:        git.mynetwork.com
    ports:
      - "0.0.0.0:myport1:myport1/tcp"
    networks:
      - default
      - ops

  cis:
    image: cis
    hostname:                 cis.mynetwork.com
    ports:
      - "0.0.0.0:myport2:myport2/tcp"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:rw
    networks:
      - default
      - ops
    depends_on:
      git:
        condition:   service_started

in /etc/hosts:

myip           git                 git.innovanon.com
myip           cis                 cis.innovanon.com
2
  • 1
    You'd need to know the Docker name of the Compose network. The commented-out myproject_default is a likely candidate, but it will depend on the current directory name and the COMPOSE_PROJECT_NAME environment variable normally. Make sure you are using the short names like git and cis. Commented Nov 2, 2023 at 10:34
  • I overlooked that I have a port mapping on the git server. Using the internal port 22 works. Your comment helped me realize that it wasn't a DNS issue after all. Commented Nov 9, 2023 at 23:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.