In the first solution, a single web server (which you do not want), all is shared already. Regardless if you use four volumes that mount into a subfolder of the container’s /var/www/html/
, or if you use a single volume that mounts some shared parent folder into that location, Apache/PHP will simply see sub-directories and files in /var/www/html/
without knowing anything about different source volumes.
You can make any shared data more explicit by adding yet another volume (maybe an in-memory volume if you’re on Linux) through which your devices can share data. (Also, you’re already sharing a database.)
If you meant the second solution: the four separate web servers can also share a dedicated volume to access each other’s data. However, as in the second solution they will be running on different port numbers and/or (sub)domains, browsers will not share data. Like: browsers will not share cookies between the four servers, as they are considered to be different servers.
I don’t understand what you’re trying to say here.
Aside, I know all is new to you, but maybe the first solution is clearer if you create an image for that. That’s what Docker is about after all! Like, not tested:
FROM php:7.4-apache
RUN docker-php-ext-install mysqli
# Copy some overview page that links to the next devices
COPY ./start-page/index.html /var/www/html/
# Copy the current versions of the current devices into the
# web root, all having an index.php file as the entry point
COPY ./body-scale-v1/ /var/www/html/weight
COPY ./thermometer/src/php/ /var/www/html/temperature
COPY ./sleep-analyzer/ /var/www/html/sleep
COPY ./blood-pressure/v3/ /var/www/html/bp
Above, I used a few different naming strategies for the source paths, like body-scale-v1
and blood-pressure/v3/
, just to explain how you could copy current (versions of) devices into the image, and still end up with the same URL like http://localhost/weight
and http://localhost/bp
whenever you update something. (Aside: versioning should probably be done in source control. Different topic.)
With the above Dockerfile
, you would copy different sources into a single image which you could use in your docker-compose.yml
from your first post, but without the volume (the “bind mount”) ./src:/var/www/html/
that obscures the contents of /var/www/html/
. Without that bind mount, instead of looking at your file system for the source files, the container would use the files that you copied into your own image.
Also, though using a container per device is nice, I’d recommend implementing a much easier solution first, to get to know Docker and maybe even PHP. This will also make clear if you have additional requirements, like you’ve now mentioned sharing data between devices.