How to activate all virtual hosts in a Docker container

Asked

Viewed 186 times

0

Considering the files below, how can I build enable all virtual hosts (present in the volume: . /Apache/)?

Docker-Compose.yaml:

version: "3.3"
services:
  mysql:
    container_name: mysql
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: myapp
      MYSQL_USER: root
      MYSQL_PASSWORD: root
    restart: always
    ports:
      - 3306:3306

  web:
    container_name: web
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ../Desenvolvimento Web/:/var/www
      - ./Apache/:/etc/apache2/sites-available/
    working_dir: /var/www
    depends_on:
      - mysql
    links:
      - mysql
    restart: always
    ports:
      - 80:80

Dockerfile:

FROM php:7.0-apache

RUN apt-get update && apt-get upgrade -y && \
    apt-get install -y \
    bzip2 curl git less mysql-client sudo unzip zip \
    libbz2-dev libfontconfig1 libfontconfig1-dev \
    libfreetype6-dev libjpeg62-turbo-dev libpng12-dev libzip-dev && \
    rm -rf /var/lib/apt/lists/*

RUN docker-php-ext-install bz2 && \
    docker-php-ext-configure gd \
        --with-freetype-dir=/usr/include/ \
        --with-jpeg-dir=/usr/include/ && \
    docker-php-ext-install gd && \
    docker-php-ext-install iconv && \
    docker-php-ext-install opcache && \
    docker-php-ext-install pdo_mysql && \
    docker-php-ext-install zip && \
    a2enmod rewrite && \
    service apache2 restart

RUN curl -sS https://getcomposer.org/installer \
    | php -- --install-dir=/usr/local/bin --filename=composer

1 answer

0

Based on your Docker-Compose, web views your mysql instance by the name "mysql".

OBS:

Its definition of:

ports:
    - 3306:3306

in mysql, it is only useful for you to host access mysql, whether with Workbench or other tool, is not related to your web container.

  • I understood, but in my case, I have locally in the directory: . /Apache/ the files referring to the virtual hosts being mounted in the container at: /etc/apache2/sites-available/, what I want is during the build to register these virtual hosts, to avoid having to enter the container and run an a2ensite...

  • Registering your virtual hosts is an apache-only operation, Docker only needs to expose its port 80 and 443, while a dns must direct the request to its host that has the container.

  • I am aware. But through the Docker file it is possible to run "instructions" inside the container, so I believe it is possible to use this feature to activate the existing virtual hosts in the shared volume. That’s what I want to do initially, already the future entries I will record myself.

  • If this is something to run on apache, it must be on dockerfile or a executed sh script or dockerfile, or the application run

Browser other questions tagged

You are not signed in. Login or sign up in order to post.