Docker: Is it possible to exchange data between two containers without volume?

I have 2 containers: web and nginx . When I create a web container, static assets for the interface are generated in the container.

Now I want to split these assets between web and nginx without using a volume on the host machine. Otherwise, I will have to create these static resources on the host side, and then include it as a volume in the web container and share it with the nginx container. This is undesirable from my point of view of the build system.

Is there a way to create static resources in a web container and then share them with nginx ?

+6
source share
1 answer

Otherwise, I will have to create these static assets on the host side and then include it as a volume in the web container and share it with the nginx container.

This statement seems incorrect.

If static assets are generated as part of the build process, then simply mount the volume on top of this directory at run time. Docker will take care of copying the base content in that, after which you can access it in your nginx container using --volumes-from .

For example, if I start with this Dockerfile for my web container:

 FROM alpine RUN apk add --update darkhttpd COPY assets /assets CMD ["darkhttpd", "/assets"] 

Now I have a /assets directory containing my static assets. If I run this image as:

 docker run -v /assets --name web web 

Then /assets will (a) be volume and (b) contain the contents of the /assets directory.

Now you can start the nginx container and share this data with it:

 docker run --volumes-from web nginx 

The nginx container will have a /assets directory that contains static assets.

I have compiled a small example here .

+1
source

All Articles