Answer the question
In order to leave comments, you need to log in
Why can't I mount a folder from another container into a container?
Two containers are launched, nginx and php-fpm.
The sources (php files, assets, files uploaded by users) are located in php-fpm in the /app folder and nginx should see them.
The best thing I could dig up on the net was to make a shared volume and copy everything from /app to this volume when starting the php container. But, firstly, this is some kind of game, because the / app folder weighs dofiga (how seriously does someone live?), And secondly, nginx will not see the files uploaded by users.
Is there really no way to create a volume that will mount a folder not from the host, but from the container?
UPD Example.
First container:
docker build -t image -f Dockerfile .
docker run -d --name container1 -v app:/app image
FROM alpine:3.9
WORKDIR /app
COPY index.html script.sh ./
CMD ["script.sh"]
<h1>Hello, Docker!</h1>
docker volume create shared
docker run -d --name container2 -p 80:80 -v shared:/usr/share/nginx/html:ro nginx:1.13
Answer the question
In order to leave comments, you need to log in
Take the data out of the container and you will be happy, well, at the same time, take care that you have two containers that do not decide to write to the same file at the same time.
Stage 1. Stateless
Build one image for both nginx and php-fpm containers, in which you will have the application code in / app and the necessary packages will be installed. Here you should only have data that does not change while the application is running. You start both containers, just for one, the entry point will be nginx, and for the other, php-fpm. Together, they will take up disk space only according to the size of the image, tk. it will be the same readonly layer
Stage 2. Statefull
All data that changes while the application is running must live in a separate storage that will be connected to both containers somewhere in /app/storage, be it just a named volume, some kind of rbd ceph or s3 storage (in this case, nginx sends there simply through the locations defined for such data)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question