Overlay on volumes in docker compose

Hey guys,

I hope you are well!

I’m relatively new to Docker, so I’m still learning how it all works. I am currently building WordPress environments using the OpenLiteSpeed ​​web server, following my Dockerfile and Docker Compose configuration.

However, I have a problem. I’m trying to create a persistent volume that maps to the WordPress HTML folder. But when docker-compose up is run, the WordPress files seem to disappear. It appears that when Docker Compose creates a folder on the host, it replaces the container folder in /opt/wordpress. If I run Compose without specifying “volumes:”, everything works fine. But as soon as I try to map the volume for persistence, the folder with the WordPress files is restored.
I put some spaces in the links in the dockerfile because as I am a new user, I can only publish with a maximum of 2 links in the message.

Could you help me find out what’s wrong?

Thanks!

Dockerfile:

FROM ubuntu:22.04

ARG OLS_VERSION=1.8.1
ARG WP_VERSION=6.5.3
ARG PHP_VERSION=lsphp82

RUN apt-get update && apt-get install wget curl cron tzdata -y

RUN wget https:// openlitespeed . org/packages / openlitespeed-$OLS_VERSION.tgz &&
tar xzf openlitespeed-$OLS_VERSION.tgz && cd openlitespeed && ./install.sh &&
echo ‘cloud-docker’ > /usr/local/lsws/PLAT && rm -rf /openlitespeed && rm /openlitespeed-$OLS_VERSION.tgz

RUN apt-get install unzip mysql-client $PHP_VERSION $PHP_VERSION-common $PHP_VERSION-mysql $PHP_VERSION-opcache
$PHP_VERSION-curl $PHP_VERSION-imagick $PHP_VERSION-redis $PHP_VERSION-memcached $PHP_VERSION-intl -y

RUN [“/bin/bash”, “-c”, “if [[ $PHP_VERSION == lsphp7* ]]; then apt-get install $PHP_VERSION-json -y; fi”]

RUN wget -O /usr/local/lsws/admin/misc/lsup.sh
https:// raw. githubusercontent. com/litespeedtech/openlitespeed/master/dist/admin/misc/lsup.sh &&
chmod +x /usr/local/lsws/admin/misc/lsup.sh

RUN curl -O https: //raw. githubusercontent. com/wp-cli/builds/gh-pages/phar/wp-cli.phar &&
chmod +x wp-cli.phar && mv wp-cli.phar /usr/bin/wp &&
ln -s /usr/local/lsws/$PHP_VERSION/bin/php /usr/bin/php

EXPOSE 7080
ENV PATH=“/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin”

ADD docker.conf /usr/local/lsws/conf/templates/docker.conf
ADD httpd_config.conf /usr/local/lsws/conf/httpd_config.conf
ADD setup_docker.sh /usr/local/lsws/bin/setup_docker.sh
ADD httpd_config.xml /usr/local/lsws/conf/httpd_config.xml
ADD htpasswd /usr/local/lsws/admin/conf/htpasswd
ADD php.ini /usr/local/lsws/lsphp82/etc/php/8.2/litespeed/php.ini
RUN /usr/local/lsws/bin/setup_docker.sh && rm /usr/local/lsws/bin/setup_docker.sh

#------ COGNALABS ------#
RUN cd /var/www/vhosts/localhost/ &&
rm -r /var/www/vhosts/localhost/html && \
wget https: //wordpress. org/wordpress-$WP_VERSION.zip &&
unzip wordpress-$WP_VERSION.zip &&
rm wordpress-$WP_VERSION.zip &&
mv /var/www/vhosts/localhost/wordpress /opt/wordpress

mv /var/www/vhosts/localhost/wordpress /var/www/vhosts/localhost/html

#ADD wp-config-docker.php /var/www/vhosts/localhost/html/wp-config.php
ADD wp-config-docker.php /opt/wordpress/wp-config.php
#RUN chown -R 1000:1000 /var/www/vhosts/localhost/html/
RUN chown -R 1000:1000 /opt/wordpress
#------ COGNALABS ------#

RUN chown 999:999 /usr/local/lsws/conf -R
RUN cp -RP /usr/local/lsws/conf/ /usr/local/lsws/.conf/
RUN cp -RP /usr/local/lsws/admin/conf /usr/local/lsws/admin/.conf/
#RUN sed -i “s|fcgi-bin/lsphp|/usr/local/lsws/$PHP_VERSION/bin/lsphp|g” /usr/local/lsws/conf/httpd_config.conf
RUN [“/bin/bash”, “-c”, “if [[ $PHP_VERSION == lsphp8* ]]; then ln -sf /usr/local/lsws/$PHP_VERSION/bin/lsphp /usr/local/lsws/fcgi-bin/lsphp8; fi”]
RUN [“/bin/bash”, “-c”, “if [[ $PHP_VERSION == lsphp8* ]]; then ln -sf /usr/local/lsws/fcgi-bin/lsphp8 /usr/local/lsws/fcgi-bin/lsphp; fi”]
RUN [“/bin/bash”, “-c”, “if [[ $PHP_VERSION == lsphp7* ]]; then ln -sf /usr/local/lsws/$PHP_VERSION/bin/lsphp /usr/local/lsws/fcgi-bin/lsphp7; fi”]
RUN [“/bin/bash”, “-c”, “if [[ $PHP_VERSION == lsphp7* ]]; then ln -sf /usr/local/lsws/fcgi-bin/lsphp7 /usr/local/lsws/fcgi-bin/lsphp; fi”]
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT [“/entrypoint.sh”]
WORKDIR /var/www/vhosts/

Docker compose:
name: teste

services:
mariadb:
image: mariadb:10.5.9
volumes:
- /home/cogna/teste/data:/var/lib/mysql:delegated"
environment:
MYSQL_ROOT_PASSWORD:
MYSQL_DATABASE:
MYSQL_USER:
MYSQL_PASSWORD:
restart: always
networks:
- default

wordpress:
image: ols-cogna-wordpress:2.0.0
ports:
- 8080:80
- 7080:7080
restart: always
volumes:
- /home/cogna/teste/html:/opt/wordpress/
environment:
WORDPRESS_DB_HOST: mariadb
WORDPRESS_DB_NAME:
WORDPRESS_DB_USER:
WORDPRESS_DB_PASSWORD:
networks:
- default

PHP MyaAdmin

phpmyadmin:

image: bitnami/phpmyadmin:5.2.0-debian-11-r43

ports:

- 8080:8080

- 8443:8443

environment:

DATABASE_HOST: mariadb

restart: always

networks:

- default

redis:
image: “redis:alpine”
logging:
driver: none
# command: redis-server --requirepass 8b405f60665e48f795752e534d93b722
volumes:
- /home/cogna/teste/data:/var/lib/redis
- /home/cogna/teste/data:/usr/local/etc/redis/redis.conf
environment:
- REDIS_REPLICATION_MODE=master
restart: always
networks:
- default
networks:
default:
driver: bridge


Please, format your post according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.

Example code block:

```
services:
  service1:
    image: image1
```

After fixing your post, please send a new comment so people are notified about the fixed content.