Docker Create Two Bridges That Corrupts My Internet Access

Error creating default bridge network: cannot create network (docker0): conflicts with network (docker0): networks have same bridge name

The Problem seems to be in /var/docker/network/. There are a lot of sockets stored that reference the bridge by its old id. To solve the Problem you can delete all sockets, delete the interface and then start docker but all your container will refuse to work since their sockets are gone. In my case I did not care about my stateless containers anyway so this fixed the problem:

ip link del docker0
rm -rf /var/docker/network/*
mkdir /var/docker/network/files
systemctl start docker
# delete all containers
docker ps -a | cut -d' ' -f 1 | xargs -n 1 echo docker rm -f
# recreate all containers

How to configure docker to be able to have internet access via wireless connection?

I see two possibility:

1) Make sure your ip_forward is set to 1 (sysctl -w net.ipv4.ip_forward=1)

2) Make sure it is not a DNS issue: try docker run base ping google.com, if it does not work, you can set custom dns server: docker run -dns 8.8.8.8 base ping google.com.

Docker Compose networking: Bridge driver with access to host machine

Your containers always have access to your host machine.

Under Linux, you can just use the address of the default gateway inside the container; this will be the address of the bridge on your host to which your container is attached. Any host services that are listening on all interfaces will be available at this address. Assuming your container has the iproute package installed, you could get the gateway address using something like:

ip route | awk '$1 == "default" {print $3}'

You could of course use the address of any host interface and pass that it as an environment variable (docker run -e HOSTADDR=192.168.23.5 ...); using the gateway address is convenient because it is discoverable from inside the container.

Under Docker for MacOS or Docker for Windows, you can use the special hostname host.docker.internal to refer to the host, as documented for example here.

Note that if your host service is not listening on all interfaces or if you have a restrictive firewall configuration, you may need to make changes before the above will work.

Understanding Docker network isolation

docker-compose creates a network for those two containers to be able talk to each-other when you run it, through a DNS service which will contain pointers to each service, by name.

So from the perspective of the pgadmin container, the dbserver can be reached under hostname db-service (because that is what you named your service in the docker-compose.yml file).

So, that traffic does not go through the host, as you were assuming, but through the aforementioned network.

For proof, docker exec -it [name-of-pg-admin-container] /bin/sh and type:
ping db-service. You will see that docker provides a DNS resolution and that you can even open a connection to the normal postgres port there.

multiple mysql containers only one is working

They all use same network and port is used. It does not corrupt or show an error but not working. I added MYSQL_TCP_PORT to each service to work on different port(3307 not included) and it is working fine.

version: '3'
services:
mysql1:
image: mysql:5.7.33
container_name: mysql1
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: db1
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: db1
MYSQL_PASSWORD: db1
SERVICE_TAGS: dev
SERVICE_NAME: mysql
MYSQL_TCP_PORT: 3306
volumes:
- mysql1:/var/lib/mysql/
- ./etc/mysql/my1.cnf:/etc/mysql/my.cnf
networks:
- app-network

mysql2:
image: mysql:5.7.33
container_name: mysql2
restart: unless-stopped
tty: true
ports:
- "3310:3310"
environment:
MYSQL_DATABASE: db2
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: db2
MYSQL_PASSWORD: db2
SERVICE_TAGS: dev
SERVICE_NAME: mysql
MYSQL_TCP_PORT: 3310
volumes:
- mysql2:/var/lib/mysql/
- ./var/log/mysql:/var/log/mysql
- ./etc/mysql/my2.cnf:/etc/mysql/my.cnf
- ./var/transit/:/var/transit
networks:
- app-network

mysql3:
image: mysql:5.7.33
container_name: mysql3
restart: unless-stopped
tty: true
ports:
- "3308:3308"
environment:
MYSQL_DATABASE: db3
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: db3
MYSQL_PASSWORD: db3
SERVICE_TAGS: dev
SERVICE_NAME: mysql
MYSQL_TCP_PORT: 3308
volumes:
- mysql3:/var/lib/mysql/
- ./var/log/mysql:/var/log/mysql
- ./etc/mysql/my3.cnf:/etc/mysql/my.cnf
- ./var/transit/:/var/transit
networks:
- app-network

mysql4:
image: mysql:5.7.33
container_name: mysql4
restart: unless-stopped
tty: true
ports:
- "3309:3309"
environment:
MYSQL_DATABASE: db4
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: db4
MYSQL_PASSWORD: db4
SERVICE_TAGS: dev
SERVICE_NAME: mysql
MYSQL_TCP_PORT: 3309
volumes:
- mysql4:/var/lib/mysql/
- ./etc/mysql/my-4.cnf:/etc/mysql/my.cnf
networks:
- app-network

# PHPMYADMIN
phpmyadmin:
image: phpmyadmin
container_name: phpmyadmin
environment:
PMA_USER: root
PMA_PASSWORD: root
PMA_HOSTS: mysql1,mysql2,mysql3,mysql4
PMA_PORTS: 3306,3310,3308,3309
links:
- mysql1
- mysql2
- mysql3
- mysql4
restart: always
ports:
- 8080:80
networks:
- app-network

#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
phpmyadmin:
driver: local
studioweb:
driver: local
sessions:
driver: local
mysql1:
driver: local
mysql2:
driver: local
mysql3:
driver: local
mysql4:
driver: local


Related Topics



Leave a reply



Submit