What is the equivalent of –add-host=host.docker.internal:host-gateway in a Compose file

The actual Docker Compose equivalent is achieved by appending the same string to the extra_hosts parameters (#Doc) as: version: ‘3.9’ services: postgres: image: postgres:14.1-bullseye environment: POSTGRES_PASSWORD: **** ports: – “5433:5432” extra_hosts: – “host.docker.internal:host-gateway” You can see it has been successfully mapped to the IP of the docker0 interface, here 172.17.0.1, from inside your container, e.g.: …

Read more

Docker 1.10 access a container by its hostname from a host machine

As answered here there is a software solution for this, called DNS Proxy Server. $ sudo ./dns-proxy-server $ docker run –rm –hostname nginx.dev nginx $ ping nginx.dev PING nginx.dev (172.17.0.4) 56(84) bytes of data. 64 bytes from 172.17.0.4 (172.17.0.4): icmp_seq=1 ttl=64 time=0.043 ms 64 bytes from 172.17.0.4 (172.17.0.4): icmp_seq=2 ttl=64 time=0.022 ms

no internet inside docker-compose service

Check /etc/default/docker to ensure it doesn’t have the following line: DOCKER_OPTS=”–iptables=false” Also check /etc/docker/daemon.json to ensure it doesn’t have the following key: { “iptables”:false } We added this on one server to get UFW working with docker. We then changed to an external firewall. Spent ages looking for the reason external networking wasn’t working because …

Read more

Start container with multiple network interfaces

With Docker 1.12+ it’s possible to add more than one network interface to a docker container with about five lines of shell commands. First: you must create the Docker networks network1 and network2 via docker network create shell command: docker network create –driver=bridge network1 –subnet=172.19.0.0/24 docker network create –driver=bridge network2 –subnet=172.19.1.0/24 notes: in this example …

Read more

Restrict Internet Access – Docker Container

As found here, I got this to work with docker-compose. Save as docker-compose.yml: version: ‘3’ services: outgoing-wont-work: image: alpine networks: – no-internet command: ping -c 3 google.com # will crash internal-will-work: image: alpine networks: – no-internet command: ping -c 3 internal-and-external internal-and-external: image: alpine networks: – no-internet – internet command: ping -c 3 google.com networks: …

Read more

How make openvpn work with docker

Solution (TL;DR;) Create /etc/openvpn/fix-routes.sh script with following contents: #!/bin/sh echo “Adding default route to $route_vpn_gateway with /0 mask…” ip route add default via $route_vpn_gateway echo “Removing /1 routes…” ip route del 0.0.0.0/1 via $route_vpn_gateway ip route del 128.0.0.0/1 via $route_vpn_gateway Add executable bit to the file: chmod o+x /etc/openvpn/fix-routes.sh. Change owner of this file to …

Read more