Docker-compose with extra_hosts fails, but docker build add-host succeeds

Viewed 253

Why can't I map this docker command, which pip installs packages from a local network repository hosted at nexus.corp.com:

$> docker build -t demo --no-cache --add-host nexus.corp.com:1.2.3.4 . 

which succeeds, into this docker-compose configuration:

version: "3"

services:
  app:
    build:
      context: .
    extra_hosts: ['nexus.corp.com:1.2.3.4']
    command: >
      sh -c "ping -c 4 nexus.corp.com"

which fails during the build step involving pip installing packages from the local repository?

Dockerfile

FROM python:3.8-slim

ENV PYTHONUNBUFFERED 1

# Install postgres client
RUN apt-get update
RUN apt-get install -y python3.8-dev 

# For testing/debugging
RUN apt-get install -y iputils-ping


RUN pip install -U pip setuptools


WORKDIR /work
COPY ./pip.conf /etc/pip.conf  # use custom pip config, see below

# Install a package hosted at the custom location
RUN pip3 install custom_package

pip.conf

[global]
index = https://nexus.corp.com/repository/corp-pypi-group/pypi
index-url = https://nexus.corp.com/repository/corp-pypi-group/simple

All of this networking is going on through a VPN, so the nexus.corp.com name isn't being served out by a DNS.

0 Answers
Related