Does Fly Ignore Docker Volumes?

Fly is executing the Dockerfile, but I also read that there is a Fly-specific way to define (persistent) volumes.

In my Dockerfile I have:

VOLUME /app/data

In my fly.toml I have:

[mounts]
  source="app_data"
  destination="/app/data"

What will happen in this case?

What would happen if I delete the volume from the Dockerfile?

The volumes live on Fly.io servers, so it has nothing to do with your local machine.

You have to use the CLI to provision a volume with a name. In this case that name is app_data. When the machine spins up, it attaches a volume from a pool of volumes with the names app_data.

The destination, is the location on the VM where that volume will be mounted too.

I use docker compose locally, and I attach volumes on my local machine all the time to validate functionality before deploying. But it has nothing to do with Fly volumes.

That being said, I don’t have the VOLUME baked into the docker image, as much as docker compose inserts it. So when fly reads the docker image, and builds the VM (not a docker container), the VOLUME ins’t listed at all.

Does that make sense?

1 Like

Yes, usually, some data of my service is written on the host’s filesystem; that’s why the VOLUME command is there.

So, you say Fly simply ignores all VOLUME commands in the Dockerfile?

I have not tried it, but I assume so.

Instead I would use COPY or ADD to add the files from the source file system you want to preserve and send to Fly.

ADD /app/data /app/data

The reason for the volume is because your running it locally and want to preserve data changes that happen in the docker image. For example you have a data.sqlite database you want to persist between container restarts.

For fly, the volume created with the CLI, and attached via the [mounts] sections handles that.

For local development, the Docker volume can handle that.

I have not seen that fly uses the VOLUME command but have not tried it.

Okay, I assumed what you said.

I just wanted to check if there is any undefined behavior or something going on when I have a VOLUME command.

Thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.