Docker container cannot resolve hostnames

i am creating a docker-compose.yaml file that has to create a pypi local repository and a container with a dev application i am writing. The problem is that, inspite of the fact that i have created custom network and specified hostnames, containers cannot see each other.

More specifically, pypi has to be up and running; during my tests, i ran it manually, and msalembic should use the local pypi repository to load eggs. But i can’t see the pypi host.

  • Docker TLS Security on Remote Client
  • Could not find jenkins_home folder in Ubuntu after downloading the Docker Jenkins Image
  • openshift internal docker registry repo address is no same as docker-registry service cluster ip
  • Docker ADD then RUN
  • Run Infinispan cluster with Server management console using Docker swarm
  • Alternating provisioning with Vagrant
  • version: '3'
    services:
      # Alembic MS
      msalembic:
        build:
          context: .
          dockerfile: AlembicMSDockerfile
        ports:
          - "5432:5432"
        hostname: alembicms
        volumes:
          - "${PWD}/msalembic/postgres/psql_data:/var/lib/postgresql/data"
        environment:
          POSTGRES_USER: ${PGUSER}
          POSTGRES_PASSWORD: ${PGPASSWORD}
          POSTGRES_DB: goodboy
          ENVIRONMENT: ${ENVIRONMENT}
        networks:
          - custom_network
        depends_on:
            - pypi
      # Private internal Pypi repository
      pypi:
        build:
            context: pypi
            dockerfile: Dockerfile
            args:
              HTACCESS: ${HTACCESS}
        hostname: pypi
        volumes:
          - "${PWD}/pypi/:/srv/pypi:rw"
        ports:
          - "9090:80"
        container_name: pypi
        networks:
          - custom_network
    networks:
      custom_network:
    

    Contents of the AlembicMSDockerfile:

    FROM python:3.6
    MAINTAINER Bruno Ripa <XXX>
    #RUN pip install -f http://pypi:9090 --trusted-host pypi alembicms
    RUN ping pypi
    ENTRYPOINT ["alembicms"]
    

    Of course i can browse and publish packages in the local pypi repository.

    Thanks.

  • outcome of Running two dockerfiles
  • how to make docker client connect to docker daemon over http
  • Openshift doesn't copy docker container files to persistence volume
  • How to connect Docker from another host?
  • docker file not found
  • Docker images with architecture optimisation?
  • One Solution collect form web for “Docker container cannot resolve hostnames”

    The port mapping you specified is only relevant when the ports of a container are exposed to the host network (e.g. if you want to access them from your host via http://localhost:9090).

    When linking containers inside a docker network, the services are exposed on the ports defined in the Dockerfile. So, according to your port mapping, the pypi container exposes port 80, which you should also use when you want to access it from another container in the same docker network.

    So, when you run the built image of AlembicMSDockerfile, you can access your pypi container on port 80 via the docker network. In your special case, you want to access the pypi container already during build time of the alembic ms image. This is currently not supported within docker-compose as you can read from the issues here.

    As long as this is not released, you could probably run the pypi container on its own and use the docker build --net=host --add-host=pypi_on_host:<yourhostip> --file=AlembicMSDockerfile and then modify the RUN command to use http://pypi_on_host:9090 (where you need the mapped port, as you no longer access it using a docker internal network). Not really elegant, but at least there is no direct reference to your host IP in the Dockerfile then…

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.