Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial-network should not be added to docker build #7520

Closed
turicas opened this issue Feb 6, 2025 · 6 comments · Fixed by #7580
Closed

initial-network should not be added to docker build #7520

turicas opened this issue Feb 6, 2025 · 6 comments · Fixed by #7580

Comments

@turicas
Copy link
Contributor

turicas commented Feb 6, 2025

Description of problem

I added an initial network ("global-net") for a new app and tried to deploy it using git:from-image and it failed:

ERROR: network mode "global-net" not supported by buildkit - you can define a custom network for your builder using the network driver-opt in buildx create

The problem occurs because Dokku calls docker to build the image with the following command:

docker image build \
	--label=dokku \
	--label=org.label-schema.schema-version=1.0 \
	--label=org.label-schema.vendor=dokku \
	--label=com.dokku.image-stage=build \
	--label=com.dokku.builder-type=dockerfile \
	--label=com.dokku.app-name=test-app-1 \
	--label=org.label-schema.schema-version=1.0 \
	--label=org.label-schema.vendor=dokku \
	--label=dokku \
	--network=global-net \
	-t dokku/test-app-1:latest .
# got after executing `dokku git:from-image` with trace on (see below how to reproduce)

... but --network in docker image build does not refer to a Docker network, it expects the networking mode for the RUN instructions during build.
The Docker semantics is not consistent in this case (and it sucks), since in docker run, the --network connects a container to a network (it should be called --networking-mode in docker build image).
I looked for an way to actually attach the network during the build phase and looks like it's not possible, so Dokku should remove the --network=<initial-network>. After some research I think the problem is in this line.

Steps to reproduce

APP_NAME="test-app-1"
NET_NAME="global-net"
APP_IMAGE="nginx:1.27.3-alpine-perl"

# Ensure network exists
sudo docker network rm "$NET_NAME" 2> /dev/null
dokku network:create "$NET_NAME"

# Ensure we have a fresh new app
echo "$APP_NAME" | dokku apps:destroy "$APP_NAME" 2> /dev/null
dokku apps:create "$APP_NAME"

# Set initial network and deploy from image
dokku network:set "$APP_NAME" initial-network "$NET_NAME"
dokku git:from-image "$APP_NAME" "$APP_IMAGE"

# =====> Setting initial-network to global-net
# -----> Generating build context
#        Setting Dockerfile
# -----> Image exists on host, skipping pull
# -----> Updating git repository with specified build context
#        Detected branch, setting deploy-branch to stable
# -----> Cleaning up...
# -----> Building test-app-1 from Dockerfile
# [+] Building 0.0s (0/0)                                                                                                                                      docker:default
# ERROR: network mode "global-net" not supported by buildkit - you can define a custom network for your builder using the network driver-opt in buildx create
#  !     Removing invalid image tag dokku/test-app-1:latest
#  !     App build failed

The same problem will happen if I have a global initial-network set (instead of setting it for the app specifically).

The problem won't happen if I set the initial-network after deploying the image (but only if no global initial-network is set):

APP_NAME="test-app-2"
NET_NAME="global-net"
APP_IMAGE="nginx:1.27.3-alpine-perl"

# Ensure network exists
sudo docker network rm "$NET_NAME" 2> /dev/null
dokku network:create "$NET_NAME"

# Ensure we have a fresh new app
echo "$APP_NAME" | dokku apps:destroy "$APP_NAME" 2> /dev/null
dokku apps:create "$APP_NAME"

# Unset global initial-network, deploy from image, set app network and restart
dokku network:set --global initial-network
dokku git:from-image "$APP_NAME" "$APP_IMAGE"
dokku network:set "$APP_NAME" initial-network "$NET_NAME"
dokku ps:restart "$APP_NAME"

dokku network:report $APP_NAME --format json | jq '."network-initial-network"'
# "global-net"

dokku report $APP_NAME

N/A

Additional information

No response

Output of failing commands after running: dokku trace:off

Output of failing commands after running: dokku trace:on

turicas added a commit to PythonicCafe/pydokku that referenced this issue Feb 6, 2025
@josegonzalez
Copy link
Member

Probably what we need to do is pass the IMAGE_SOURCE_TYPE (flag.Arg(1)) into network.TriggerDockerArgsProcess() here (and the related places). If the value is dockerfile, do not print out the initial-network. We'd also only want to do this for the build phase, so splitting this out into a separate function is probably best.

@josegonzalez
Copy link
Member

Related issue: docker/buildx#175

@josegonzalez
Copy link
Member

Correct way to use a network during builds is to use a custom builder it seems. Thats a bit frustrating...

@turicas
Copy link
Contributor Author

turicas commented Feb 12, 2025

Correct way to use a network during builds is to use a custom builder it seems. Thats a bit frustrating...

So would need to create a builder per app, with its initial networks (global and specific)? Something like docker buildx create --name dokku_builder_app_APPNAME --driver docker-container --driver-opt network=netname

josegonzalez added a commit that referenced this issue Mar 9, 2025
The network flag is unsupported by the docker image build command under buildx (which is default now).

Closes #7520
@josegonzalez
Copy link
Member

Closing as there is a pull request open.

@turicas
Copy link
Contributor Author

turicas commented Mar 9, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants