-
Notifications
You must be signed in to change notification settings - Fork 599
[docker-in-docker] - Move the iptables switching logic in the docker-init script and isolated tests for specific cases #1666
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
Open
Kaniska244
wants to merge
16
commits into
devcontainers:main
Choose a base branch
from
Kaniska244:add-test-d-in-d
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5b19874
Check the tests
Kaniska244 4cad3da
check the log
Kaniska244 43e9b83
Adding debug statements
Kaniska244 6349dd2
Another change
Kaniska244 3d7b7f0
Check in docker-init.sh
Kaniska244 08c8731
Change test order
Kaniska244 a5838b2
Check the presence of the kernel module
Kaniska244 ef0ba8e
change the test execution order
Kaniska244 f0a10b4
Changes in workflows
Kaniska244 c6a12a6
Change the test
Kaniska244 b8312b4
Further isolation
Kaniska244 67847c8
Adding a flag to switch the logic for better management.
Kaniska244 ddd313a
Modify stress tests
Kaniska244 7f2a5ed
Merge branch 'main' into add-test-d-in-d
Kaniska244 7360873
Add docker-compose latest version
Kaniska244 66c9cfd
Changing to minor version upgrade as a switch flag is present
Kaniska244 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| docker_compose_latest_no_moby.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| # Definition specific tests | ||
| check "docker compose" bash -c "docker compose version | grep -E '[0-9]+\.[0-9]+\.[0-9]+'" | ||
| check "docker-compose" bash -c "docker-compose --version | grep -E '[0-9]+\.[0-9]+\.[0-9]+'" | ||
| check "installs compose as docker-compose" bash -c "[[ -f /usr/local/bin/docker-compose ]]" | ||
|
|
||
| # Report result | ||
| reportResults |
22 changes: 22 additions & 0 deletions
22
test/docker-in-docker/docker_iptables_switch_at_install.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| # Default behavior (iptablesSwitchAtRuntime omitted -> false): switching happens | ||
| # at image build time, so docker-init.sh should NOT contain the runtime block. | ||
| check "init-script-exists" bash -c "test -f /usr/local/share/docker-init.sh" | ||
| check "no-runtime-iptables-block" bash -c "! grep -q 'update-alternatives --set iptables' /usr/local/share/docker-init.sh" | ||
|
|
||
| # The build-time switch should have set /etc/alternatives/iptables to one of the | ||
| # known backends. With the ip_tables module loaded on the host, legacy is preferred. | ||
| check "iptables-alternative-set" bash -c "readlink /etc/alternatives/iptables | grep -E 'iptables-(legacy|nft)$'" | ||
| check "iptables works" sudo iptables -L | ||
|
|
||
| check "version" docker --version | ||
| check "docker-ps" bash -c "docker ps" | ||
|
|
||
| # Report result | ||
| reportResults |
24 changes: 24 additions & 0 deletions
24
test/docker-in-docker/docker_iptables_switch_at_runtime.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| # iptablesSwitchAtRuntime=true: switching is deferred to container start, so the | ||
| # runtime block MUST have been written into docker-init.sh by install.sh. | ||
| check "init-script-exists" bash -c "test -f /usr/local/share/docker-init.sh" | ||
| check "runtime-iptables-block-present" bash -c "grep -q 'update-alternatives --set iptables' /usr/local/share/docker-init.sh" | ||
| check "runtime-iptables-block-has-legacy-branch" bash -c "grep -q '/usr/sbin/iptables-legacy' /usr/local/share/docker-init.sh" | ||
| check "runtime-iptables-block-has-nft-branch" bash -c "grep -q '/usr/sbin/iptables-nft' /usr/local/share/docker-init.sh" | ||
|
|
||
| # The runtime block runs as part of docker-init.sh (the feature's entrypoint), | ||
| # so by the time these tests execute the alternative must already be set. | ||
| check "iptables-alternative-set" bash -c "readlink /etc/alternatives/iptables | grep -E 'iptables-(legacy|nft)$'" | ||
| check "iptables works" sudo iptables -L | ||
|
|
||
| check "version" docker --version | ||
| check "docker-ps" bash -c "docker ps" | ||
|
|
||
| # Report result | ||
| reportResults |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| # Stress scenario: validates the docker daemon works when the iptables | ||
| # alternative switching is deferred to container start (iptablesSwitchAtRuntime=true). | ||
| check "init-script-exists" bash -c "test -f /usr/local/share/docker-init.sh" | ||
| check "runtime-iptables-block-present" bash -c "grep -q 'update-alternatives --set iptables' /usr/local/share/docker-init.sh" | ||
|
|
||
| check "version" docker --version | ||
| check "docker-ps" bash -c "docker ps" | ||
| check "log-exists" bash -c "ls /tmp/dockerd.log" | ||
| check "log-for-completion" bash -c "cat /tmp/dockerd.log | grep 'Daemon has completed initialization'" | ||
| check "log-contents" bash -c "cat /tmp/dockerd.log | grep 'API listen on /var/run/docker.sock'" | ||
|
|
||
| # Report result | ||
| reportResults |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| # Feature specific tests | ||
| check "iptables works" sudo iptables -L | ||
| check "iptables uses legacy" bash -c "iptables --version | grep legacy" | ||
|
|
||
| check "version" docker --version | ||
| check "docker-ps" bash -c "docker ps" | ||
| check "log-exists" bash -c "ls /tmp/dockerd.log" | ||
| check "log-for-completion" bash -c "cat /tmp/dockerd.log | grep 'Daemon has completed initialization'" | ||
| check "log-contents" bash -c "cat /tmp/dockerd.log | grep 'API listen on /var/run/docker.sock'" | ||
|
|
||
| # Report result | ||
| reportResults | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| # Feature specific tests | ||
| check "iptables works" sudo iptables -L | ||
| check "iptables uses legacy" bash -c "iptables --version | grep legacy" | ||
|
|
||
| check "version" docker --version | ||
| check "docker-ps" bash -c "docker ps" | ||
| check "log-exists" bash -c "ls /tmp/dockerd.log" | ||
| check "log-for-completion" bash -c "cat /tmp/dockerd.log | grep 'Daemon has completed initialization'" | ||
| check "log-contents" bash -c "cat /tmp/dockerd.log | grep 'API listen on /var/run/docker.sock'" | ||
|
|
||
| # Report result | ||
| reportResults | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| # Feature specific tests | ||
| check "docker-ps" bash -c "docker ps" | ||
| # Fail loudly if dockerd never finished initializing, printing the real error | ||
| check "dockerd-started-successfully" bash -c ' | ||
| if ! grep -q "Daemon has completed initialization" /tmp/dockerd.log; then | ||
| echo "❌ Docker daemon failed to start. Last errors from /tmp/dockerd.log:" | ||
| echo "----- dockerd.log (tail) -----" | ||
| tail -n 100 /tmp/dockerd.log | ||
| echo "----- error/fatal lines -----" | ||
| grep -iE "error|fatal|failed|panic" /tmp/dockerd.log || true | ||
| exit 1 | ||
| fi | ||
| ' | ||
| check "log-for-completion" bash -c "cat /tmp/dockerd.log | grep 'Daemon has completed initialization'" | ||
|
|
||
| check "iptables works" sudo iptables -L | ||
| check "iptables uses nf_tables" bash -c "iptables --version | grep nf_tables" | ||
|
|
||
| check "version" docker --version | ||
| check "docker-ps" bash -c "docker ps" | ||
| check "log-exists" bash -c "ls /tmp/dockerd.log" | ||
| check "log-for-completion" bash -c "cat /tmp/dockerd.log | grep 'Daemon has completed initialization'" | ||
| check "log-contents" bash -c "cat /tmp/dockerd.log | grep 'API listen on /var/run/docker.sock'" | ||
|
|
||
| # Report result | ||
| reportResults | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| # Feature specific tests | ||
| check "iptables works" sudo iptables -L | ||
| check "iptables uses nf_tables" bash -c "iptables --version | grep nf_tables" | ||
|
|
||
| check "version" docker --version | ||
| check "docker-ps" bash -c "docker ps" | ||
| check "log-exists" bash -c "ls /tmp/dockerd.log" | ||
| check "log-for-completion" bash -c "cat /tmp/dockerd.log | grep 'Daemon has completed initialization'" | ||
| check "log-contents" bash -c "cat /tmp/dockerd.log | grep 'API listen on /var/run/docker.sock'" | ||
|
|
||
| # Report result | ||
| reportResults | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably the only thing I'd try to make a case for, but I'm not overly familiar with this repos general policy here so if it tends to more conservative then that's ok:
If you're moving to a v4 release it might be worth making this a
default: truesince you're already cutting a major rev.Reason: The only time it matters what iptables is present is at runtime so it's probably the correct approach, someone can always opt into the old behaviour if they wish (by setting it to false) but you'll probably see some "why doesn't docker run" issues similar to #1659.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I would much rather put it back to version 3 as the flag could help doing this seamlessly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering since 3.0.0 and 3.0.1 break on Ubuntu 24.04 devcontainer base images on a nUbuntu 26.04 host anyway and my testing indicates that the 3.1.0/4.0.0 feature works also on an Ubuntu 22.04 why not considering this a fix with a new compatible feature with the default of
iptablesSwitchAtRuntime:true? This makes the 3.x feature working; are there any side effects of the iptablesSwitchAtRuntime?