I'm using docker-compose to setup my php project locally. This works under normal circumstances effortlessly. I've done this many times, but today I ran into a strange problem. One of my containers won't lookup the dns of the others and I can't explain why.
docker-compose exec app sh
nslookup db
Server: 127.0.0.11
Address: 127.0.0.11:53
** server can't find db.fritz.box: NXDOMAIN
it tries to lookup fritz.box? okay, let's check resolv.conf
cat /etc/resolv.conf
search fritz.box
nameserver 127.0.0.11
options edns0 trust-ad ndots:0
nslookup db 127.0.0.11
Server: 127.0.0.11
Address: 127.0.0.11:53
Non-authoritative answer:
Non-authoritative answer:
Name: db
Address: 172.18.80.3
No clue what's going on. Fun fact calling "db @127.0.0.11" works. But I can't tell php to do so. So what's the problem? Let's check db (after install:
nslookup app
Server: 127.0.0.11
Address: 127.0.0.11#53
Non-authoritative answer:
Name: app
Address: 172.18.80.2
Works like a charm. /etc/resolv.conf does look like exactly like the one in php's container. Why can't my docker image lookup the service db correctly? What am I missing here?
For reference my docker-compose.yml looks like:
version: "3.8"
services:
web:
image: nginx:1.23-alpine
ports:
- 8080:80
volumes:
- .docker/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./:/var/www/html
app:
build:
context: .docker/php/
volumes:
- ./:/var/www/html
working_dir: /var/www/html
db:
image: mariadb:10.4
command: ["--innodb-flush-method", "O_DIRECT"]
ports:
- 3306:3306
environment:
- MYSQL_DATABASE
- MYSQL_USER
- MYSQL_PASSWORD
- MYSQL_ROOT_PASSWORD
My app's Docker context is just adding some php extensions to the official php-image:
FROM php:7.4.30-fpm-alpine
RUN apk add --no-cache \
freetype \
libpng \
libjpeg-turbo \
freetype-dev \
libpng-dev \
libjpeg-turbo-dev \
gmp \
gmp-dev \
zip \
libzip-dev \
fcgi
RUN docker-php-ext-configure zip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
&& docker-php-ext-install -j${NPROC} gd \
&& docker-php-ext-install -j${NPROC} zip
COPY fpm-pool.conf /etc/php/7.4/fpm/pool.d/www.conf
COPY --from=composer /usr/bin/composer /usr/bin/composer
# https://github.com/renatomefi/php-fpm-healthcheck#docker-example
COPY php-fpm-healthcheck /usr/local/bin/php-fpm-healthcheck
RUN set -xe && echo "pm.status_path = /status" >> /usr/local/etc/php-fpm.d/zz-docker.conf
EXPOSE 9000
HEALTHCHECK --interval=5s --timeout=1s \
CMD php-fpm-healthcheck || exit 1