Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker-compose volumes working with Dockerfile : Device or resource busy

I get an issue working with docker-compose service while using Dockerfile build.

Indeed, I provide a .env file into my app/ folder. I want the TAG value of the .env file to be propagate/render into the config.ini file. I tried to achieve using entrypoint.sh (which is launch just after the volumes) but it failed.

There is my docker-compose.yml file

# file docker-compose.yml

version: "3.4"

app-1:
  build: 
    context: ..
    dockerfile: deploy/Dockerfile
  image: my_image:${TAG}
  environment:
    - TAG=${TAG}
    volumes:
      - ../config.ini:/app/config.ini

And then my Dockerfile:

# file Dockerfile

FROM python:3.9
RUN apt-get update -y
RUN apt-get install -y python-pip
COPY ./app /app
WORKDIR /app
RUN pip install -r requirements.txt
RUN chmod 755 entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["python", "hello_world.py"]

In my case, I mount a config.ini file with the configuration like :

# file config.ini

[APP_INFO]
name = HELLO_WORLD
version = {TAG}

And finally, in my app folder, I have a .env file where you can found the version of the app, which is evoluing through time.

# file .env 

TAG=1.0.0

Finally

#!/bin/bash

echo "TAG:${TAG}"

awk '{sub("{TAG}","${TAG}")}1' /app/config.ini > /app/final_config.ini

mv /app/final_config.ini /app/config.ini

exec "$@" # Need to execute RUN CMD function

I want my entrypoint.sh (which is called before the last DOCKERFILE line and after the docker-compose volumes. With the entrypoint.sh, I want overwritte my mounted file by a new one, cerated using awk. Unfortunatly, I recover the tag and I can create a final_config.ini file, but I'm not able to overwrite config.ini with it.

I get this error :

mv: cannot move '/app/final_config.ini' to '/app/config.ini': Device or resource busy

How can I overwritting config.ini without getting error? Is there an more simple solution?

like image 328
PicxyB Avatar asked Oct 18 '25 19:10

PicxyB


1 Answers

Because /app/config.ini is a mountpoint, you can't replace it. You should be able to rewrite it, like this...

cat /app/final_config.ini > /app/config.ini

...but that would, of course, modify the original file on your host. For what you're doing, a better solution is probably to mount the template configuration in an alternate location, and then generate /app/config.ini. E.g, mount it on /app/template_config.ini:

    volumes:
      - ../config.ini:/app/template_config.ini

And then modify your script to output to the final location:

#!/bin/bash

echo "TAG:${TAG}"

awk '{sub("{TAG}","${TAG}")}1' /app/template_config.ini > /app/config.ini

exec "$@" # Need to execute RUN CMD function
like image 164
larsks Avatar answered Oct 20 '25 12:10

larsks