file.txt
temporarily inside that container. As soon as the container shuts down, that file and data is destroyed. This isn’t great when you’re training data and want your information to persist past your LLM training.
Because of this, we need to persist data outside the container. Let’s take a look at a workflow you can use to persist data outside a container.
/data
, touches a file called current_date.txt
, and copies our script.
entrypoint.sh
script is updated:
/data/current_date.txt
file instead of printing it.
/data/current_date.txt
file instead of printing it.
Finally, we can mount the named volume to this data directory:
date-volume
Docker volume to the /data directory in the container. Anything written to /data
inside the container will now be written to the date-volume
on the host instead of the container’s ephemeral file system. This allows the data to persist. Once the container exits, the date output file is safely stored on the host volume.
After the container exits, we can exec into another container sharing the volume to see the persisted data file:
date-volume
.
v date-volume:/data mount
point maps the external volume dir to /data
again.cat /data/current_date.txt
command prints out the file with the date output from the first container.--rm
flag removes the container after running so we don’t accumulate stopped containers.