How do I mount a home directory onto a volume?

I’m trying to setup a little bastion instance that I can ssh into and use to run migrations against a fly postgres instance.

I’d like to mount my home directory (/root) to a volume so it sticks around, but it doesn’t seem to be doing so.

Here’s my fly.toml:

app = 'sfce-bastion'
primary_region = 'sea'

[build]


[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1

[mounts]
source = "bastion"
destination = "/root"

And my docker file:

FROM ubuntu:latest

# Update Ubuntu Software repository
RUN apt-get update

# Set the locale
RUN apt-get install -y locales && \
    locale-gen en_US.UTF-8 && \
    update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8

# Install psql
RUN apt-get install -y postgresql-client

# Install wget and unzip
RUN apt-get install -y wget unzip

# Install golang migrate
RUN wget https://github.com/golang-migrate/migrate/releases/download/v4.14.1/migrate.linux-amd64.tar.gz
RUN tar -xvf migrate.linux-amd64.tar.gz
RUN mv migrate.linux-amd64 /usr/local/bin/migrate

RUN apt-get install -y git

# Clean up
RUN apt-get clean

I have a volume:

$ fly volumes list

vol_r7lllg2mzn9w3x94	created	bastion	3GB 	sea   	891e	true     	d891d19f643258	  21 hours ago	

Which appears to be mounted to my machine:

$ fly machines list

d891d19f643258	polished-dew-8113	stopped	sea   	sfce-bastion:deployment-01HSEHWK554CQH2YKZKEZ16C0H	fdaa:8:a95b:a7b:f9:14d3:e70d:2	vol_r7lllg2mzn9w3x94	2024-03-19T20:55:16Z	2024-03-20T18:27:42Z	v2          	app          shared-cpu-1x:1024MB	

But why I run fly console, I don’t see my volume mounted.

> fly console
Created an ephemeral machine 148e537dc04768 to run the console.
Connecting to fdaa:8:a95b:a7b:248:bb15:6a5e:2... complete
root@148e537dc04768:/# df
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/vda         8154588 302256   7416520   4% /
shm               111292      0    111292   0% /dev/shm
tmpfs             111292      0    111292   0% /sys/fs/cgroup

I would expect to see something that says Mounted on /root. What gives?

Hey there,

I would try adding the following to the end of your Dockerfile:

CMD ["tail", "-f", "/dev/null"]

Then re-run fly deploy .

Once that deploys, you should be able to verify things by ssh’ing via:

fly ssh console

I hope that helps.

Note that when Fly mounts a volume for the first time, it does not automatically copy over the contents of what’s already included in the destination directory within the Docker image. I wonder if there’s something special about /root in the Docker image that prevents a volume from mounting over it and effectively erasing it.

I asked for Automatic volume initialization like in Docker last year, but understandably Fly probably has a thousand higher priority things to work on.

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