我正在尝试使用以下 Dockerfile 扩展 Apache 2 Docker 容器:
FROM joomla:3-apache-php7
RUN apt-get update
RUN a2enmod ssl
RUN printf "\nIncludeOptional /data/apache/conf-enabled/*.conf\n" >> /etc/apache2/apache2.conf
RUN printf "include_path = '.:/data/php/conf.d'" > /usr/local/etc/php/conf.d/additional.ini
RUN bash -c 'mkdir -pv /data/{apache/conf-enabled,php/conf.d}'
RUN ln -s /etc/apache2/sites-enabled/ /data/apache/sites-enabled
VOLUME ["/var/www/html/", "/data/apache/", "/data/php/"]
EXPOSE 80 443
ENTRYPOINT ["/entrypoint.sh"]
CMD ["apache2-foreground"]
当我尝试启动容器时,会出现:
root@n06 / # docker-compose up -d
root@n06 / # docker-compose logs container
apache2: Syntax error on line 223 of /etc/apache2/apache2.conf: Could not open config directory /data/apache/conf-enabled: No such file or directory
当我注释掉RUN printf "\nIncludeOptional /data/apache/conf-enabled/*.conf\n" >> /etc/apache2/apache2.conf
并登录到正在运行的容器时:
root@1c72507b2024:/# ls -la /data/**
/data/apache:
total 8
drwxr-xr-x 2 root root 4096 Sep 3 11:39 .
drwxr-xr-x 5 root root 4096 Sep 3 11:50 ..
/data/php:
total 8
drwxr-xr-x 2 root root 4096 Sep 3 11:39 .
drwxr-xr-x 5 root root 4096 Sep 3 11:50 ..
创建的目录随机消失,有时 /data/apache/conf-enabled 目录在那里。
编辑
docker-compose.yml:
version: '2'
networks:
main:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.18.0.0/16
gateway: 172.18.0.1
services:
test:
build: docker/test
container_name: test
networks:
- main
volumes:
- /mnt/docker/test/joomla:/var/www/html
- /mnt/docker/test/apache:/data/apache/
- /mnt/docker/test/php:/data/php/
- /etc/letsencrypt:/etc/letsencrypt
- /var/lib/letsencrypt:/var/lib/letsencrypt
- /etc/localtime:/etc/localtime
links:
- mariadb:mariadb
environment:
- JOOMLA_DB_USER=test
- JOOMLA_DB_PASSWORD=test
- JOOMLA_DB_HOST=mariadb
- JOOMLA_DB_NAME=test