0

As I understand a docker-compose file, using the docker-compose up command, loads the images and starts the containers. Conversely using a Dockerfile file with the docker build command creates the image only. I think I am missing something here as things aren't working as I'd like.

Following the bitnami/wordpress instructions I got an install running fine using docker-compose up d. Can then access via localhost:81

version: '2'
services:
  mariadb:
    image: bitnami/mariadb:latest
    volumes:
      - /path/to/mariadb-persistence:/bitnami/mariadb
  wordpress:
    image: bitnami/wordpress:latest
    depends_on:
      - mariadb
    ports:
      - '81:80'
      - '443:443'
    volumes:
      - ./wordpress-persistence:/bitnami/wordpress
      - ./apache-persistence:/bitnami/apache
      - ./php-persistence:/bitnami/php

Because I want to be able to access this as domain.com.dev, I looked at implementing nginx-proxy. Following the instructions there, and with some inspiration from Docker nginx-proxy : proxy between containers, I came up with the following:

version: '2'
services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    restart: always
    ports:
      - "88:80"
    volumes:
      - "/var/run/docker.sock:/tmp/docker.sock:ro"

  mariadb:
    image: bitnami/mariadb:latest
    volumes:
      - //c/websites/domain_com/mariadb-persistence:/bitnami/mariadb
  domain.com.dev:
    image: bitnami/wordpress:latest
    depends_on:
      - mariadb
    ports:
      - '81:80'
    environment:
      - VIRTUAL_HOST=domain.com.dev
    volumes:
      - //c/websites/domain_com/wordpress-persistence:/bitnami/wordpress
      - //c/websites/domain_com/apache-persistence:/bitnami/apache
      - //c/websites/domain_com/php-persistence:/bitnami/php

Running docker-compose up -d with this appears to complete without error. However when I access domain.com.dev in a browser, I get a default Index of / page, which suggests I somehow got partway there but not all the way. Looking at the local folders, they get created but it seems like the wordpress-persistence does not get populated, which could explain the default view in the browser.

Any thoughts on why this isn't coming up as expected? Something obvious I missed?

Community
  • 1
  • 1
Grant Palin
  • 4,546
  • 3
  • 36
  • 55

1 Answers1

0

1) For the first approach, you need "to finish" the configuration. If you don't have a running webserver (nginx, apache, etc.) (on port 80) - just change the port from 81 to 80:

ports:
      - '80:80'
      - '443:443'

and add the record "127.0.0.1 domain.com.dev" to your hosts file (/etc/hosts in linux).

P.S. you may change port from 88 to 80 at the second approach - it will work without changing hosts file

If you have a running wevserver on port 80 - then it is needed to you proxy directives at virtualhost config file. Here is an example:

server {
    listen 80 default_server;
    server_name _;

    include expires.conf;

    location / {
        proxy_set_header Host              $host;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://172.17.0.1:81;
        proxy_http_version 1.1;
    }
}

2) The second approach is usually used with dnsmasq configuration. Use this and this links to get more detailed information and examples of configuration.

malyy
  • 859
  • 5
  • 10