I am working on a flask application that runs on some embedded hardware inside a Docker container and I am trying to store persistent data in a named volume that exists on my host machine during the image build. I have my docker-compose.yml set up to create and mount the volume when the container is started, however the volume is empty when it is created. I have several files on my host at /src/data that need to populate the app/src/data folder on my embedded hardware after the volume is mounted.
I have found of lot of places talking about copying files into volumes, but I can’t seem to find the information I need to make this happen from an image.
I had read somewhere about potentially using a busybox container to copy the data into the volume prior to starting my container, due to the volume being set up after the data was placed in the folder causing it to be obscured as long as the volume existed, but the init/busybox method has not worked for me.
Here is my docker-compose.yml:
version: "3.9"
services:
init:
image: busybox
volumes:
- ./src/data:/src/data:ro
- appdata:/dest/data
command: sh -c "cp -r /src/data/* /dest/data/"
myapp-debug:
build:
context: .
dockerfile: Dockerfile.debug
volumes:
- appdata:/app/src/data
image: ${LOCAL_REGISTRY}:5002/myapp-debug:${TAG}
ports:
- 6502:6502
- 6512:6512
- 5000:5000
- 502:502
depends_on:
- init
myapp:
build:
context: .
dockerfile: Dockerfile
volumes:
- appdata:/app/src/data
image: ${DOCKER_LOGIN}/myapp:${TAG}
ports:
- 5000:5000
- 502:502
restart: always
depends_on:
- init
volumes:
appdata:
It seems like this should be a relatively easy task to do, but I am not having any luck with it. Copying the files manually is not an option as this same image will be used in production programming over many duplicates of the same device.
Dave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.