While building custom images (like extending the cm) I've seen various networking issues when on VPN. I noticed that containers can reach the internet with docker compose up but the same resources can't be reached during build.

Is there way way to specify a custom network when building images in docker-compose.yml?

1 Answer 1


A few observations I've made while working over VPN (in particular Palo Global Protect):

  • Container networking appears to get disrupted when the VPN disconnects. Tearing down the containers with docker compose down and then docker compose up -d appears to correct the issue. I think this is because a new network is created which doesn't conflict with the VPN.
  • The running containers use the new network which may be why containers can reach the internet.
  • Building containers use the default network. Creating a new network and associating it with the build would create a similar scenario as the running containers.

Start by creating a new build.ps1:


$networkResult = docker network inspect build-nat | ConvertFrom-Json
if(!$networkResult) {
    docker network create --driver nat build-nat
docker compose -f .\docker-compose.build.yml build $Services
docker network rm build-nat

Add the network to your build section in docker-compose.yml:

    context: ./docker/build/node
    network: build-nat

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.