0

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

I also tried this docker-compose.yml :

version: '3.8'

services:
    website:
        build: 
            context: ./drupal-6-lts
    volumes:
        - ./drupal-6-lts:/var/www/html
    network_mode: host

but then I got this error when executing docker compose build :

services.network_mode must be a mapping

I tried to use my physical adress too but it didn't help either

Sianurh
  • 1
  • 1
  • Try to set mysql host as host.docker.internal and remove the network=host key value. – sachin Mar 17 '21 at 13:31
  • `volumes:` and `network_mode:` need to be indented to the same level as `build:`, so they're properties of `website:`. – David Maze Mar 17 '21 at 13:43
  • @sachin I tried that too but it doesn't work either. (I have this error in the drupal install : "Failed to connect to your MySQL database server. MySQL reports the following message: Connection refused. Are you sure you have the correct username and password? Are you sure that you have typed the correct database hostname? Are you sure that the database server is running?" and the answer is yes for the three questions except for the database hostname ) – Sianurh Mar 17 '21 at 13:44
  • @DavidMaze When I do that I get this error on docker compose up : "Error response from daemon: network-scoped alias is supported only for containers in user defined networks" – Sianurh Mar 17 '21 at 13:46
  • Host networking generally disables Docker's networking system, so if you have any other network-related options, they're not going to be compatible with that. The canonical question you link to gives some alternatives that aren't host networking (even on native Linux where there isn't `host.docker.internal`). – David Maze Mar 17 '21 at 13:53
  • 1
    @Sianurh get a shell on any running container, install ping(or any other network tool) and try to ping to host.docker.internal ? If the ping is success, this is not a network issue. – sachin Mar 17 '21 at 14:35

0 Answers0