How to configure a shared resource between the containers?

Colleagues, Hello!

# Development configuration
version: "3.7"


 # Php application
 restart: on-failure
 context: .
 dockerfile: ./docker/php/Dockerfile-dev
 - ./:/www/
 - ./docker/php/log:/var/log
 - ./docker/php/usr/local/etc/php/conf.d:/usr/local/etc/php/conf.d
 - type: bind
 source: ./images
 target: /www/images
 - db
 - db
 - 9000
 PHP_INI_SCAN_DIR: "/usr/local/etc/php/conf.d"
 TZ: "Europe/Moscow"


 # Api Nginx admin server
 container_name: rapp.nginx-images
 restart: on-failure
 image: nginx:latest
 - ./docker/nginx/dev/nginx.conf:/etc/nginx/nginx.conf
 - ./docker/nginx/dev/sites-enabled/vhost-images.conf:/etc/nginx/sites-enabled/vhost-images.conf
 - type: bind
 source: ./images
 read_only: true
 target: /www/images
 - app
 - 80
 command: ["nginx", "-g", "daemon off;"]

I want to have a shared folder between the two containers.
With this configuration I have achieved some results.
I have a common resource in a folder with images.

But the problem is that the service nginx-images blocks the file and I can't change it from the app

Get the error message.

Warning: unlink(/www/images/1/categories/385d87d3d566437ca99b1161e93d78db-5e406295b30e1.jpeg): Device or resource busy

There is a possibility that it is not in the configuration, and nginx is doing something with my file.
April 7th 20 at 10:53
1 answer
April 7th 20 at 10:55
From the documentation

Tom, the benefits of using.

  • Backup
  • Control using the Docker CLI
  • Tom's work on Linux and Windows containers.
  • Volume can more safely share between containers
  • Drivers of volumes allow you to store volumes on remote hosts or in the cloud, encrypting the contents of the volumes, or to add other functions.

It is suitable for my problem.
I'm working on a RESTful API and it would be foolish to use the same server for the distribution of images.
In my opinion, to hand out static it is better to allocate a separate container.

As for my problem.
Yes, indeed, as I suspected in the beginning, nginx was blocking the file.

Special thanks to @ferocactus
His comments

Igor, well, obviously, nginx is blocking the file. How exactly - I don't know, it depends on the file system and the kinds of operations that nginx performs. The same would be without the Docker, whether these services are neighbours on the same server.
I would start with the "open_file_cache off" in the nginx configuration

Got to the heart of the problem.

The parameter of the open_file_cache default is set to off
But in my case it was included and chalk settings different from off

As for the parameter of the open_file_cache
Syntax: open_file_cache off;
open_file_cache max=N [inactive=time];
open_file_cache off;
Context: http, server, location
Sets the cache that can store:

  • open file descriptors
  • information about their sizes and modification time
  • information on existence of directories

Thank you all.

Find more questions by tags Docker