R
R
Ruslan Ruslanov2019-09-27 12:15:30
Apache HTTP Server
Ruslan Ruslanov, 2019-09-27 12:15:30

How to properly connect virtual hosts in docker/apache2?

I am mastering docker, I want to launch nginx in parallel for a separate application, and apache for a bitrix box on a local machine.
Nginks configured, hosts are connected, everything works.
And here with the Apache there were problems.
I do not understand the principle of connecting Apache hosts. If everything is ok with nginx, I changed something in the host, rebooted the container and you are glad that everything is working, then Apache has some kind of crap already at the stage of connecting hosts.
I tried to connect through the assembly of the dockerfile, but I get the following error (there is no such directory, but how can I access the hosts folder then?):

Building apache
Step 1/6 : FROM httpd:latest
 ---> 19459a872194
Step 2/6 : COPY ./hosts/apache2/sites-available/ /etc/apache2/sites-available
ERROR: Service 'apache' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder011831039/hosts/apache2/sites-available: no such file or directory

Apache dockerfile itself:
FROM httpd:latest
COPY ./hosts/apache2/sites-available/ /etc/apache2/sites-available
RUN a2dissite /etc/apache2/sites-available/000-default.conf
RUN a2dissite /etc/apache2/sites-available/default-ssl.conf
RUN a2ensite /etc/apache2/sites-available/bitrix.conf
RUN service apache2 restart #я не знаю, нужно ли перезапускать в контейнере сервис...

I also tried like this:
FROM httpd:latest

# COPY ./hosts/apache2/sites-available/ /etc/apache2/sites-available

RUN a2dissite ./hosts/apache2/sites-available/000-default.conf
RUN a2dissite ./hosts/apache2/sites-available/default-ssl.conf
RUN a2ensite ./hosts/apache2/sites-available/bitrix.conf

# RUN a2dissite /etc/apache2/sites-available/000-default.conf
# RUN a2dissite /etc/apache2/sites-available/default-ssl.conf
# RUN a2ensite /etc/apache2/sites-available/bitrix.conf

RUN service apache2 restart

Error (no command? how is that?):
Building apache
Step 1/5 : FROM httpd:latest
 ---> 19459a872194
Step 2/5 : RUN a2dissite ./hosts/apache2/sites-available/000-default.conf
 ---> Running in 63d83aa87984
/bin/sh: 1: a2dissite: not found
ERROR: Service 'apache' failed to build: The command '/bin/sh -c a2dissite ./hosts/apache2/sites-available/000-default.conf' returned a non-zero code: 127

docker-compose.yml:
version: "3.7"
services:

  apache:
    container_name: apache
    image: httpd:latest
    ports:
      - "732:732"
    volumes:
      - ../../www:/var/www     
      - ./hosts/apache2:/usr/local/apache2/conf
      - ./logs/apache2:/usr/local/apache2/logs
    # command:
    #   - a2dissite /etc/apache2/sites-available/000-default.conf
    #   - a2dissite /etc/apache2/sites-available/default-ssl.conf
    #   - a2ensite /etc/apache2/sites-available/bitrix.conf
    #   - service apache2 restart
    depends_on:
      - php

  nginx:
    container_name: nginx
    image: nginx:latest
    ports:
      - "740:740"
    volumes:
      - ../../www:/var/www
      - ./hosts/nginx:/etc/nginx/conf.d
      - ./logs/nginx:/var/log/nginx
    depends_on:
      - php

  php:
    container_name: php
    build: ./images/php
    volumes:
      - ../../www:/var/www
    links:
       - mysql:db

  mysql:
    container_name: mysql
    image: mysql
    ports: 
      - "3306:3306"
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root

  adminer:
    image: adminer
    restart: always
    ports:
      - "8080:8080"
    links:
      - mysql:db

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2019-09-27
@q2digger

Look, here is a link to the Dockerfile of the official
Apache httpd container installed in /usr/local/apache2 , and the directory structure is something like this.

➜  ~ docker exec -it d1d45faeeb6e /bin/bash
[email protected]:/usr/local/apache2# pwd
/usr/local/apache2
[email protected]:/usr/local/apache2#
[email protected]:/usr/local/apache2# ls -la
total 56
drwxr-sr-x 1 www-data www-data 4096 May  8 02:05 .
drwxrwsr-x 1 root     staff    4096 May  8 02:03 ..
drwxr-sr-x 2 root     www-data 4096 May  8 02:05 bin
drwxr-sr-x 2 root     www-data 4096 May  8 02:05 build
drwxr-sr-x 2 root     www-data 4096 May  8 02:05 cgi-bin
drwxr-sr-x 4 root     www-data 4096 May  8 02:05 conf
drwxr-sr-x 3 root     www-data 4096 May  8 02:05 error
drwxr-xr-x 7     1000     1000 4096 Nov 19  2018 htdocs
drwxr-sr-x 3 root     www-data 4096 May  8 02:05 icons
drwxr-sr-x 2 root     www-data 4096 May  8 02:05 include
drwxr-sr-x 1 root     www-data 4096 Sep 25 15:02 logs
drwxr-sr-x 2 root     www-data 4096 May  8 02:05 modules

S
Sanes, 2019-09-27
@Sanes

What the hell is pulling docker for the LAMP stack?
Judging by the config, this is the Bitrix environment. Runs and works great on LXD. A container with Nginx Proxy is placed in front.
You will hide on NAT, you will almost certainly have problems with the environment.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question