wodby / docker4drupal

Docker-based Drupal stack
https://wodby.com/docker4drupal
MIT License
1.24k stars 531 forks source link

Confused about how to set this up with static or custom IPs #349

Open kevinquillen opened 5 years ago

kevinquillen commented 5 years ago

Codebase Built-in

Describe your issue I am using Docker for Mac 2.0.0.2.

I want to set the internal IP of the containers to not be on 172.x.x.x. According to the documentation I can do this by setting the subnet and bip/fixd-cidr in Dockers daemon.json file or from the configuration UI of the software.

I was able to get an IP assigned just once for Docker4Drupal to be 192.168.32.x - subsequent retries have resulted in only 172.x.x.x no matter what I do.

I have tried pruning and killing containers and starting over multiple times.

I need to avoid using 172.x.x.x IP internally because we have various internal network services in the office that resolve to those IPs. When trying to make the application talk to those services to fetch data, it fails because the DNS returns an IP that the container cannot resolve. It works if it does not use 172.x.x.x IP.

Where in the docker-compose.yml or traefik.yml can I override or figure out why Docker4Drupal won't adhere to the settings in the Docker for Mac application?

A screenshot for reference is included.

Output of docker info

Containers: 7
 Running: 7
 Paused: 0
 Stopped: 0
Images: 52
Server Version: 18.09.1
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9754871865f7fe2f4e74d43e2fc7ccd237edcbce
runc version: 96ec2177ae841256168fcf76954f7177af9446eb
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.125-linuxkit
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.952GiB
Name: linuxkit-025000000001
ID: 2ADD:GVMI:TTFE:PL2D:HO6H:DCER:D7VQ:C5BF:OC7Q:KBNN:G6ZK:D25E
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 84
 Goroutines: 100
 System Time: 2019-01-22T21:56:49.3917117Z
 EventsListeners: 3
HTTP Proxy: gateway.docker.internal:3128
HTTPS Proxy: gateway.docker.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

Contents of your docker-compose.yml

version: "3"

services:
  mariadb:
    image: wodby/mariadb:$MARIADB_TAG
    container_name: "${PROJECT_NAME}_mariadb"
    stop_grace_period: 30s
    environment:
      MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
      MYSQL_DATABASE: $DB_NAME
      MYSQL_USER: $DB_USER
      MYSQL_PASSWORD: $DB_PASSWORD
#    volumes:
#      - ./mariadb-init:/docker-entrypoint-initdb.d # Place init .sql file(s) here.
#      - /path/to/mariadb/data/on/host:/var/lib/mysql # Use bind mount

  php:
    image: wodby/drupal-php:$PHP_TAG
    container_name: "${PROJECT_NAME}_php"
    environment:
      PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025
      DB_HOST: $DB_HOST
      DB_USER: $DB_USER
      DB_PASSWORD: $DB_PASSWORD
      DB_NAME: $DB_NAME
      DB_DRIVER: $DB_DRIVER
      PHP_FPM_USER: wodby
      PHP_FPM_GROUP: wodby
      COLUMNS: 80 # Set 80 columns for docker exec -it.
## Read instructions at https://wodby.com/stacks/drupal/docs/local/xdebug/
      PHP_XDEBUG: 1
      PHP_XDEBUG_DEFAULT_ENABLE: 1
      PHP_XDEBUG_REMOTE_CONNECT_BACK: 0
      PHP_IDE_CONFIG: serverName=PHPSTORM
      PHP_XDEBUG_REMOTE_HOST: host.docker.internal # Docker 18.03+ Mac/Win
      PHP_XDEBUG_REMOTE_LOG: /tmp/php-xdebug.log
    volumes:
      - ./:/var/www/html:cached # User-guided caching
      - ./drush/${PROJECT_NAME}.aliases.drushrc.php:/home/wodby/.drush/${PROJECT_NAME}.aliases.drushrc.php
      #- docker-sync:/var/www/html # Docker-sync
## For XHProf and Xdebug profiler traces
#      - files:/mnt/files

  mailhog:
    image: mailhog/mailhog
    container_name: "${PROJECT_NAME}_mailhog"
    labels:
      - 'traefik.backend=${PROJECT_NAME}_mailhog'
      - 'traefik.port=8025'
      - 'traefik.frontend.rule=Host:mailhog.${PROJECT_BASE_URL}'

  apache:
    image: wodby/apache:$APACHE_TAG
    container_name: "${PROJECT_NAME}_apache"
    depends_on:
      - php
    environment:
      APACHE_LOG_LEVEL: debug
      APACHE_BACKEND_HOST: php
      APACHE_VHOST_PRESET: php
      APACHE_DOCUMENT_ROOT: /var/www/html/docroot
    volumes:
      - ./:/var/www/html:cached # User-guided caching
      #- docker-sync:/var/www/html # Docker-sync
    labels:
      - 'traefik.backend=${PROJECT_NAME}_apache'
      - 'traefik.port=80'
      - 'traefik.frontend.rule=Host:${PROJECT_BASE_URL}'

  memcached:
    container_name: "${PROJECT_NAME}_memcached"
    image: wodby/memcached:$MEMCACHED_TAG

  portainer:
    image: portainer/portainer
    container_name: "${PROJECT_NAME}_portainer"
    command: --no-auth -H unix:///var/run/docker.sock
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      - 'traefik.backend=${PROJECT_NAME}_portainer'
      - 'traefik.port=9000'
      - 'traefik.frontend.rule=Host:portainer.${PROJECT_BASE_URL}'

  traefik:
    image: traefik
    container_name: "${PROJECT_NAME}_traefik"
    command: -c /dev/null --web --docker --logLevel=INFO
    ports:
      - '8000:80'
#      - '8080:8080' # Dashboard
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

#volumes:
## Docker-sync for macOS users
#  docker-sync:
#    external: true
## For Xdebug profiler
#  files:

traefik.yml:

version: '2'

services:
  traefik:
    image: traefik
    restart: unless-stopped
    command: -c /dev/null --web --docker --logLevel=DEBUG
    networks:
      - project1
      - project2
    ports:
      - '80:80'
      - '8080:8080'
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

networks:
  project1:
    external: 
      name: project1-dir_default
  project2:
    external:
      name: project2-dir_default

working

This was the only time I was able to not get an assigned IP of 172.x.x.x.

csandanov commented 5 years ago

I'm not sure this is the right place to ask this question since (most likely) this is not specific to docker4drupal. Considering docker provides documentation on how to use a different IP range then docker-compose probably supports it as well, my guess is that some additional configuration required in traefik. Try localizing the issue and figuring out what exactly doesn't work, if that's traefik then ask this question in their repository.

kevinquillen commented 5 years ago

Sorry, I am new to Docker and trying to transition out of Lando.

It seems that Docker Compose will not inherit settings from Docker Engine unless you explicitly declare configuration in the compose file - this is the source of my problems and you are right, this is a Docker Compose issue and not Docker4Drupal, but probably worth mentioning here.

I had to add this to the bottom of my docker-compose.yml file:

networks:
  default:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet:  10.20.1.5/24

Then, in traefik.yml, I removed the networks section and changed the config to:

services:
  traefik:
    image: traefik
    restart: unless-stopped
    command: -c /dev/null --web --docker --logLevel=DEBUG
    networks:
      - default
    ports:
      - '80:80'
      - '8080:8080'
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

Now I get the IPs I want to have, and do not have a network collision anymore.

So question, do we actually need traefik.yml? What is this file for? That wasn't clear to me in the documentation.

csandanov commented 5 years ago

traefik.yml used to run multiple projects on the same port