I tried to deploy a drupal 6 docker container that works with the host machine database (for testing purpose before deploying it to a remote database) but it just doesn't want to work despite following the different advices I found. ( particularly in this question From inside of a Docker container, how do I connect to the localhost of the machine? when it talks about host mode, so even if the question looks alike it doesn't feel like it is a duplicate )
Dockerfile
FROM php:7.3-apache
COPY . /var/www/html
EXPOSE 80
RUN chmod o+w /var/www/html/sites/default/settings.php &&\
chmod o+w /var/www/html/sites/default/files &&\
apt-get update &&\
apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev &&\
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ &&\
docker-php-ext-install mysqli gd mbstring pdo pdo_mysql &&\
docker-php-ext-enable mysqli
docker-compose.yml
version: '3.8'
services:
website:
build:
context: ./drupal-6-lts
network: host
volumes:
- ./drupal-6-lts:/var/www/html
ports:
- 8080:80
For the database connection I specified these settings :
Driver : mysqli Host : 127.0.0.1:8889 (the mysql port is 8889, I also tried to replace 127.0.0.1 by localhost) And the right username, password and database name.
The drupal installation does work when I launch it with MAMP only, but it seems that it can't do the link to the db when in the container despite the network: host
statement in docker-compose.yml
When I try Do Trung Duc solution I get this error when executing docker compose build :
services.network_mode must be a mapping