0

I have a windows 10 host, using docker desktop 4.6.1. I have a docker-compose.yml which contains the two services vpn and app. What I want to achieve is, that the build process of docker already uses the vpn containers network connection.

version: "3.8"
services:
  vpn:
    ...
  app:
    ...
    network_mode: service:vpn

The app container itself correctly uses the vpn container connection, as I could verify this by testing. But the build process seems to use the hosts network. Dockers build command has a network or networkmode argument that allows to use a specific containers network. But it gives me an error:

docker-compose.yml

version: "3.8"
services:
  vpn:
    ...
  app:
    build:
      network: container:vpn
    network_mode: service:vpn

docker compose up -d

network mode "container:vpn" not supported by buildkit. You can define a custom network for your builder using the network driver-opt in buildx create.

How would I use buildx in my example? I am quite confused by the documentation which talks about context and endpoints.

1 Answer 1

0

1.) Split those both services into two seperate compose files

docker-compose-vpn.yml

version: "3.8"
services:
  vpn:
    ...

docker-compose-app.yml

version: "3.8"
services:
  app:
    image: username:app
    container_name: app
    depends_on:
      - vpn
    network_mode: container:vpn

2.) Create and bring up vpn container

docker compose -f docker-compose-vpn.yml up -d

3.) Create a new vpn builder instance

docker buildx create --name vpn-builder --driver docker-container --driver-opt network=container:vpn --use

4.) Create image using your buildx vpn instance and publish it (--load) to docker.

docker buildx b -f Dockerfile-app --load --no-cache --tag username:app .

5.) Start the new app container

docker compose -f docker-compose-app.yml up -d

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .