I
I
Igor2020-02-09 23:18:04
Docker
Igor, 2020-02-09 23:18:04

How to correctly configure a shared resource between containers?

Colleagues, hello!

# Development configuration
version: "3.7"

services:

  # Php application
  app:
    container_name: rapp.app
    restart: on-failure
    build:
      context: .
      dockerfile: ./docker/php/Dockerfile-dev
    volumes:
      - ./:/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
    depends_on:
      - db
    links:
      - db
    expose:
      - 9000
    environment:
      PHP_INI_SCAN_DIR: ":/usr/local/etc/php/conf.d"
      TZ: "Europe/Moscow"

...

  # Nginx api admin server
  nginx-images:
    container_name: rapp.nginx-images
    restart: on-failure
    image: nginx:latest
    volumes:
      - ./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
    ports:
      - 127.0.0.100:8013:80
    depends_on:
      - app
    expose:
      - 80
    command: ["nginx", "-g", "daemon off;"]


I want to have a shared folder between two containers.
With this configuration, I have achieved some results.
I have a share in the form of a folder with images.

But the problem is that the nginx-images service is locking the file and I can't change it from the app service . I'm getting

an error.

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


There is a possibility that it's not the configuration, but nginx is doing something with my file.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2020-02-13
@IgorPI

From
Tom's documentation, benefits of using.

  • Backup
  • Management with Docker CLI
  • Volumes work on both Linux and Windows containers.
  • Volumes can be more securely split between containers
  • Volume drivers allow you to store volumes on remote hosts or in the cloud, encrypt the contents of volumes, or add other features.

This suits my task.
I'm working on a RESTful API and it would be silly to use the same server to serve images.
In my opinion, it is better to allocate a separate container for distributing statics.
As for my problem.
Yes, indeed, as I assumed at the very beginning, nginx was locking the file.
Special thanks to the user Sergey
His comments

Igor, well, it's obvious that nginx is blocking the file. How exactly - I don't know, it depends on the file system and the operations that nginx performs. The same would have happened without docker if these services were neighbors on the same server.
-------------------------------------------------- -----------------------------
I would start with "open_file_cache off" in the nginx config

Got to the heart of the problem.
The open_file_cache parameter is by default set to off
But in my case it was enabled and the options were different from off
As for the open_file_cache
parameter itself Syntax: open_file_cache off;
open_file_cache max=N [inactive=time];
Default:
open_file_cache off;
Context: http, server, location
Specifies a cache that can store:
  • open file descriptors
  • information about their dimensions and time of modification
  • information about the existence of directories

Thanks to all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question