I don’t know much about docker so expect some uninformed questions. I have Ubuntu 24.04 LTS running Docker Desktop, The Docker Desktop I downloaded from Install Docker Desktop on Linux | Docker Docs. Docker version
$ docker --version
Docker version 29.6.0, build fb59821
I went through the various walk through examples for the Welcome container. That all seemed to go well. So, I asked AI what I would need in order to build a container that runs an Apache web server with a PHP app that communicates with a MySQL database. I want to be able to use Xdebug from VSCode on my local host and be able to administer MySQL from PHPMyAdmin. It suggested the Dockerfile and docker-compose.yml files below.
When I run
$ docker compose up --build -d
The build fails. It complains that for pecl is has a temporary DNS failure
10.02 Updating channel "pecl.php.net"
25.04 Channel "pecl.php.net" is not responding over https://, failed with message: Connection to `ssl://pecl.php.net:443' failed: php_network_getaddresses: getaddrinfo for pecl.php.net failed: Temporary failure in name resolution
25.04 Trying channel "pecl.php.net" over http:// instead
35.05 Cannot retrieve channel.xml for channel "pecl.php.net" (Connection to `pecl.php.net:80' failed: php_network_getaddresses: getaddrinfo for pecl.php.net failed: Temporary failure in name resolution)
From the Ubuntu host an nslookup works just fine:
$ nslookup pecl.php.net
Server: 127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
pecl.php.net canonical name = pecl-internal-php-net.b-cdn.net.
Name: pecl-internal-php-net.b-cdn.net
Address: 212.102.40.120
AI recommended trying
docker run --rm alpine ping -c 3 8.8.8.8
That gives me 100% packet loss.
AI had me try these fixes.
Configure /etc/docker/daemon.json
{
"bip": "192.168.250.1/24",
"dns": ["8.8.8.8", "1.1.1.1"]
}
I verified that net.ipv4.ip_forward=1 is on.
AI had me use network: host in docker-compose.yml
But the build environment remained completely sandboxed.
After hours of going back and forth with AI, AI finally said to essentially copy down all the pieces I need and then configure the build to use the local pieces and not use the automatic download.
But, my objective isn’t to get a working container. It’s to learn how to use the system to create containers automatically. So, I have bailed on AI and I need to ask a real person
The files below are just kind of left over after hours of recommendations to try this and that,including moving /etc/resolv.conf from the stub file and setting POSTROUTE flags in IP. I think I undid all that stuff as none of it gained me anything. AI really seemed to be just shooting in the dark and it was getting circular. I don’t know enough to defend any of the settings in the Dockerfie and docker-compose.yml. I am not sure which ones were part of the original suggestion and what ones AI had me add or change when trying to debug the DNS issue.
I would appreciate any pointers on how I can get an automated build to work on my Ubuntu host
Thanks Chris
Dockerfile:
FROM php:8.2-apache
# Install required PHP extensions for MySQL and Xdebug
RUN docker-php-ext-install pdo pdo_mysql mysqli \
&& pecl channel-update pecl.php.net \
&& pecl install xdebug \
&& install-php-extensions xdebug
# Configure Xdebug 3
RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.log=/tmp/xdebug.log" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
docker-compose.yml:
# Newer docker will select the version.
# Setting it is redundant and can cause confusion
# version: '3.8'
services:
# Apache + PHP Service
web:
build:
context: .
network: host
ports:
- "8080:80"
volumes:
- ./src:/var/www/html
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
- XDEBUG_CONFIG=client_host=host.docker.internal
# MySQL Database Service
db:
image: mysql:8.0
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: my_database
volumes:
- db_data:/var/lib/mysql
# phpMyAdmin Service
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: always
ports:
- "8081:80"
environment:
PMA_HOST: db
PMA_USER: root
PMA_PASSWORD: rootpassword
volumes:
db_data: