I have a clear Ubuntu server with docker (bought from hosting) with additional IPs in the same subnet.
Docker Version: 27.0.2
docker-compose: 2.28.1
ubuntu: 20.04
IP Address MAC Address Subnet Mask Gateway
XXX.YY.222.146 - 255.255.255.0 XXX.YY.222.1
XXX.YY.222.147 - 255.255.255.0 XXX.YY.222.1
When I used curl with the parameter --interface XXX.YY.222.146 jsonip.com
, I received a response with the selected IP. However, I tried setting different IPs for the Docker containers. I used this test configuration.
version: '3.8'
services:
test1:
container_name: t1
build: .
command: python3 tt.py
restart: always
networks:
vpcbr:
ipv4_address: XXX.YY.222.146
test2:
container_name: t2
restart: always
build: .
command: python3 tt.py
networks:
vpcbr:
ipv4_address: XXX.YY.222.147
networks:
vpcbr:
driver: bridge
ipam:
config:
- subnet: XXX.YY.222.0/24
gateway: XXX.YY.222.1
And I receive an error message indicating that there is no internet connection available in the container.
ifconfig
br-9b0b74d3f01b: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet XXX.YY.222.1 netmask 255.255.255.0 broadcast XXX.YY.222.255
inet6 fe80::42:5dff:fee9:1725 prefixlen 64 scopeid 0x20<link>
ether 02:42:5d:e9:17:25 txqueuelen 0 (Ethernet)
RX packets 25702 bytes 719656 (719.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5143 bytes 565706 (565.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1450
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:20:fa:ca:23 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet XXX.YY.222.147 netmask 255.255.255.0 broadcast XXX.YY.222.255
inet6 fe80::be24:11ff:feec:7535 prefixlen 64 scopeid 0x20<link>
ether bc:24:11:ec:75:35 txqueuelen 1000 (Ethernet)
RX packets 10190354 bytes 1464362541 (1.4 GB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 359613 bytes 51612677 (51.6 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
iptables
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy DROP)
target prot opt source destination
DOCKER-USER all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-1 all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain DOCKER (2 references)
target prot opt source destination
Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target prot opt source destination
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
RETURN all -- anywhere anywhere
Chain DOCKER-ISOLATION-STAGE-2 (2 references)
target prot opt source destination
DROP all -- anywhere anywhere
DROP all -- anywhere anywhere
RETURN all -- anywhere anywhere
Chain DOCKER-USER (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
I am sorry if this is a simple question, but I am having difficulty with my DevOps skills and have been trying to solve this issue for several days. I have also tried registering DNS, changing the MTU, and creating a network separate from Docker-Compose, but it all leads to the same result – no internet access.