I have an image that I’ve used for a long time now that works perfectly. It allows me to spin up a new project and via the compose file, I have everything I need to hit the ground running. The one thing I’ve always been frustrated by is that apparent complexity of getting some proxies working for local development.

At the moment I get a web server that will allow me to access the running container via localhost. For my own sanity I’d love to be able to have myproject.test or something along those lines. Is there anyway this can be done via the compose file? I've tried searching for days but I can't seem to find a way to do this but it seems like something that shouldn't be so hard.

My compose file looks like:

version: ‘2’

    build: ./docker/webserver
    image: perch
      - "80:80"
      - "443:443"
      - ./www:/var/www/html
      - db
      - web-variables.env

    image: mysql:5.7
    command: mysqld --sql_mode=""
      - "3306:3306"
      - ./db:/var/lib/mysql
      - MYSQL_DATABASE=db_xxx

My Dockerfile:

FROM php:7.2-apache
RUN apt-get update -y && apt-get install -y \
        mcrypt \
        imagemagick \
        libpng-dev \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        curl \
        libcurl4-openssl-dev \
        libxpm-dev \
        libvpx-dev \
    && docker-php-ext-configure gd \
    --with-freetype-dir=/usr/lib/x86_64-linux-gnu/ \
    --with-jpeg-dir=/usr/lib/x86_64-linux-gnu/ \
    --with-xpm-dir=/usr/lib/x86_64-linux-gnu/ \
    --with-vpx-dir=/usr/lib/x86_64-linux-gnu/ \
    && docker-php-ext-install \
        pdo \
        pdo_mysql \
        gd \
        curl \
    && a2enmod \
        rewrite \
        ssl \
        actions \
        include \
        cgi \
    && service apache2 restart

1 Answers

bellackn On

AFAIK, you cannot do this only by configuring your docker-compose.yml (at least, there is no image that I know that makes this possible yet – but would be a cool thing actually!)

What you can do is mounting a pre-configured configuration file for your reverse proxy inside the webserver's container and then adapt it to your needs. What you cannot do dynamically is making your browser go to your reverse proxy by hitting http://myproject.test.* You would have to configure your /etc/hosts file for this. Of course, you can do that on your own machine, if this is sufficient for you.

(*) Ok, you could do this, but it doesn't seem like a right thing to do, please correct me if you think otherwise.