3

The setup

I have 2 docker containers running on Windows 8.1

One containing npm for building an angular project. The other containing nginx, serving the dist directory.

The dist directory is in /var/www/front, shared by both containers in volumes.

Here's the docker-compose config :

nginx:
    build: ./docker/nginx
    ports:
        - "80:80"
        - "8080:8080"
    environment:
        APP_ENV: prod
    volumes:
        - ./logs/nginx:/var/log/nginx:cached
        - ./back:/var/www/back
        - ./front:/var/www/front
node:
    build: ./docker/node
    ports:
        - "4200:4200"
    volumes:
        - ./front:/var/www/front
        - /var/www/front/node_modules/

The issue

When nginx container is running and only when the page is displayed on the browser, ng build won't build the angular project, failing with a "conflict" error :

ETXTBSY: text file is busy, unlink '/var/www/front/dist/assets/image.jpg

Is there a workaround to this issue?

1 Answer 1

2
+50

I think the Windows file system locks the files used by the second container, This can result in your error. Using named volumes to share the data between the two containers could solve this problem.

nginx:
    build: ./docker/nginx
    ports:
        - "80:80"
        - "8080:8080"
    environment:
        APP_ENV: prod
    volumes:
        - ./logs/nginx:/var/log/nginx:cached
        - ./back:/var/www/back
        - ./front:/var/www/front
        - dist:/var/www/front/dist
node:
    build: ./docker/node
    ports:
        - "4200:4200"
    volumes:
        - ./front:/var/www/front
        - dist:/var/www/front/dist
        - /var/www/front/node_modules/

volumes:
    dist:

Update :

The issue here was the front/dist output directory which was shared between the 2 containers, but also with the host, running Windows. For some reasons the files were locked on "read-only mode" when the 2 containers read them.

The solution is to create a named volume just for the output directory so that there's no binding with the host path. The 2 containers will read and write files without issues.

The only downside is that the output files will be more difficult to be accessed by the host. Example, for versioning purpose.

Sign up to request clarification or add additional context in comments.

6 Comments

Maybe but I need to mount the host path ./front to have the code updates. How can it be done with named volumes?
I added an example config for your volume. For more information take a look at the well documented docker-compose reference I linked in my post.
I did try to configure the driver earlier, but I had path errors. I got it right thanks to you... but doesn't resolve the busy-file error, unfortunately. Windows fault I imagine.
You could try to mount the volume read only in the nginx container. Maybe that helps.
I added read_only: true, with and without consistency: cached. Same error. the only solution to free the locked files is to restart the nginx container.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.