mirror of
https://github.com/containers/podman.git
synced 2025-12-05 04:40:47 +08:00
Fix Docker API compatibility with network alias (#17167)
* Add BaseHostsFile to container configuration * Do not copy /etc/hosts file from host when creating a container using Docker API Signed-off-by: Gavin Lam <gavin.oss@tutamail.com>
This commit is contained in:
10
test/compose/etc_hosts/README.md
Normal file
10
test/compose/etc_hosts/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
etc hosts
|
||||
===========
|
||||
|
||||
This test mounts a /etc/hosts file in the host containing an entry `foobar`, then create a container with an alias of the same hostname.
|
||||
|
||||
Validation
|
||||
------------
|
||||
|
||||
* No /etc/hosts entries are copied from the host. There should be only one entry of the hostname, which is IP address of the alias.
|
||||
* The hostname is resolved to IP address of the alias.
|
||||
19
test/compose/etc_hosts/docker-compose.yml
Normal file
19
test/compose/etc_hosts/docker-compose.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
version: '3.3'
|
||||
|
||||
services:
|
||||
test:
|
||||
image: alpine
|
||||
command: ["top"]
|
||||
hostname: foobar
|
||||
networks:
|
||||
net1:
|
||||
aliases:
|
||||
- foobar
|
||||
|
||||
networks:
|
||||
net1:
|
||||
driver: bridge
|
||||
ipam:
|
||||
driver: default
|
||||
config:
|
||||
- subnet: 10.123.0.0/24
|
||||
2
test/compose/etc_hosts/hosts
Normal file
2
test/compose/etc_hosts/hosts
Normal file
@@ -0,0 +1,2 @@
|
||||
127.0.0.1 localhost
|
||||
127.0.0.1 foobar
|
||||
5
test/compose/etc_hosts/setup.sh
Normal file
5
test/compose/etc_hosts/setup.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
if ! is_rootless; then
|
||||
mount --bind $TEST_ROOTDIR/etc_hosts/hosts /etc/hosts
|
||||
else
|
||||
$PODMAN_BIN unshare mount --bind $TEST_ROOTDIR/etc_hosts/hosts /etc/hosts
|
||||
fi
|
||||
5
test/compose/etc_hosts/teardown.sh
Normal file
5
test/compose/etc_hosts/teardown.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
if ! is_rootless; then
|
||||
umount /etc/hosts
|
||||
else
|
||||
$PODMAN_BIN unshare umount /etc/hosts
|
||||
fi
|
||||
12
test/compose/etc_hosts/tests.sh
Normal file
12
test/compose/etc_hosts/tests.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
# -*- bash -*-
|
||||
|
||||
ctr_name="etc_hosts_test_1"
|
||||
if [ "$TEST_FLAVOR" = "compose_v2" ]; then
|
||||
ctr_name="etc_hosts-test-1"
|
||||
fi
|
||||
|
||||
podman exec "$ctr_name" sh -c 'grep "foobar" /etc/hosts'
|
||||
like "$output" "10\.123\.0\." "$testname : no entries are copied from the host"
|
||||
|
||||
podman exec "$ctr_name" sh -c 'getent hosts foobar | awk "{print \$1}"'
|
||||
like "$output" "10\.123\.0\." "$testname : hostname is resolved to IP address of the alias"
|
||||
@@ -207,7 +207,7 @@ function start_service() {
|
||||
|
||||
$PODMAN_BIN \
|
||||
--log-level debug \
|
||||
--storage-driver=vfs \
|
||||
--storage-driver=vfs \
|
||||
--root $WORKDIR/root \
|
||||
--runroot $WORKDIR/runroot \
|
||||
--cgroup-manager=systemd \
|
||||
|
||||
Reference in New Issue
Block a user