Docker Community Forums

Share and learn in the Docker community.

Apache container requires manual "a2ensite *" on every run

(Justin Bodnar) #1

I’m sure what I’m doing has a simple solution, but I’m pulling my hair out trying to find it.

I’m running the wordpress (on apache) and mysql images in docker-compose. I’ve mounted the directories I believe are appropriate ( “/var/ww/html” and “etc/apache2/sites-available” ). so I may modify them outside the containers, and everything connects when I spin it up. The only issue is I have to manually enter the wordpress container and enable all my virtualhosts file via ‘a2ensite’. I’ve tried using bash scripts to run these commands via ‘docker exec’ and repeatedly get “site [SITENAME] does not exist” error. I added a bash script inside the container and tried running that the same way, with the same results. I figured I can mount the “/” directory of the container to my host machine but docker-compose complains when I try. Is there a better way of accomplishing this?

My docker-compose file:

version: '3.1'

    container_name: wp_ajh
    image: localhost:5000/wp_ajh:latest
    restart: always
      - '80:80'
      - '443:443'
      - /ajh/wp/html/:/var/www/html/
      - /ajh/wp/sites-available/:/etc/apache2/sites-available/

    container_name: db_ajh
    image: localhost:5000/db_ajh:latest
    restart: always
      - /ajh/db/:/var/lib/mysql
      MYSQL_USER: root

docker --version
Docker version 18.06.0-ce, build 0ffa825

docker-compose --version
docker-compose version 1.22.0, build f46880fe

uname -a
Linux debian-vps 4.9.0-7-amd64 #1 SMP Debian 4.9.110-1 (2018-07-05) x86_64 GNU/Linux

(Martin Terp) #2

Hi :slight_smile:

Why do you need to modify the virtualhost?
Normally you would add a virtualhost into the image, that listens on port 80 and points to the directory ( and/or 443 if you handle ssl in your image ) and thats it?

(Justin Bodnar) #3

Hi terpz,

Thanks for your response. My thinking was that I’d like to be able to run my setup with a freshly pulled image if necessary. I wanted to have all my configuration saved in the volumes on my host machine. I did end up pushing the configuration to the image on my private registry, as you said, but don’t want to be so dependent on the custom image. Is this outside the philosophy of Docker?

(Martin Terp) #4

If your goal is only to serve some web pages, then there should be no need to build a image your self, even php bundles with apache:

but i dont know what your demands are for your container :slight_smile:

(Justin Bodnar) #5

Hi again,

I ended up just pushing the changes to private registry as a workaround. No biggie, I don’t think what I’m trying to do is currently supported. Thanks for your help though!

(Raj Chaudhuri) #6

Creating your own image is the right thing to do, in this case. A docker image should represent a specific application. The official images are starting points - you should build your own images atop them, and use your images in your compose files or deployment stacks.

(Goffinf) #7

I don’t think using the word should is especially helpful since it suggests that if you don’t you are doing something wrong. If a community image meets your needs then I don’t see any compelling reason to rebuild it yourself unless you are prepared to assume the responsibility for its lifecycle. Sometimes that the right thing to do, other times it’s an unnecessary overhead…