edge selcuk
edge selcuk

Reputation: 179

Preserving Container Directory Contents with Docker Volume Sync

I'm encountering a challenge in a Docker setup where I aim to synchronize files between a host and a container, but face the unintended deletion of pre-setup content in the container's /app directory. This happens when an initially empty host volume is mounted to the container.

Here's the relevant content of my Dockerfile:

# Base image
FROM python:3.10

# Set working directory
WORKDIR /app

# Installations and setup
RUN apt-get update && apt-get install -y git rsync
RUN pip install --upgrade pip virtualenv
# [Additional setup commands...]

# Create directories for applications
RUN mkdir llmware_dir aider_chat_dir codeqai_dir llmlingua_dir autogen_dir
# [Further configurations and environment setups...]

# Copy and set permissions for the startup script
COPY startup.sh ./
RUN chmod +x startup.sh

# Run the startup script
CMD ["./startup.sh"]

The startup script (startup.sh):

#!/bin/bash

# Sync files from the mounted volume to /app
rsync -a /host_volume/ /app/

# Original CMD command
tail -f /dev/null

And the container is run with:

docker run -it --name llm_container -e OPENAI_API_KEY=%OPENAI_API_KEY% -v llm_volume:/host_volume llm_img

How can I ensure the /app directory contents are preserved while syncing only new or changed files from host_volume?

Upvotes: 0

Views: 27

Answers (0)

Related Questions