0

I am trying to figure out how mounts work in GCE with a hello-world program. I have an existing image and when I create a VM instance in GCE, I select this existing image. For the command, I enter echo with the argument "hello world". When the VM starts up, I can see this printed in the logs so I know it's running properly.

Before creating the VM instance, I created a standard persistent disk. When creating the VM, I chose "add volume." I specified these details for the volume:

  • Volume Type: disk
  • Mount path: /hello-world-data
  • Disk name: hello-world-test
  • Partition:
  • Mode: Read/write

After my VM is running and I see "hello world" in the logs, I go to the VM instances page and select "SSH" on the instance. This successfully opens a cloud terminal, and I'm at a prompt which properly reads <username>@hello-world-test-instance ~ $.

I ls -la, and I do not see the volume I specified: /hello-world-data.

I thought maybe it will exist when created, so I try:

cd /
mkdir hello-world-data

But I get this error:

mkdir: cannot create directory ‘hello-world-data’: Read-only file system

Now I'm confused. I created a disk, specified a mount path, and selected read/write. What's going on?

After some exploring, I see that this path exists:

/mnt/disks/gce-containers-mounts/gce-persistent-disks/hello-world-test

What's that? No docs told me about this several-directories deep path. I see if I can at least write anything inside that directory:

$ cd /mnt/disks/gce-containers-mounts/gce-persistent-disks/hello-world-test
$ touch test.txt
touch: cannot touch 'test.txt': Permission denied

On top of this, I do not even see the executables created by my Dockerfile which should be placed into the /bin directory.

So, I'm lost. Where's the volume? Why is it not at the specified mount path? Why does /bin not contain the executables created by the Dockerfile?

Thank you

cilphex
  • 6,006
  • 6
  • 34
  • 44
  • Which service are you using? Google Compute Engine ( and which OS), Google Compute Engine Container OS (COS), Google Container Engine (now called Kubernetes). Do not mix multiple problems into one question. Post more than one question instead. – John Hanley Aug 24 '20 at 19:12
  • @JohnHanley Google Compute Engine, as it says in the post. For the boot disk OS, it's whatever the GCE default is. The base image of my container is `golang:1.13-alpine`. – cilphex Aug 24 '20 at 19:17

1 Answers1

1

The answer is that when you SSH into the VM instance, you are putting yourself into the host machine and not directly into the container.

Once you're in the host machine, you can get into the container by doing docker ps to find the container ID, then doing docker exec -it <container-id> bash (if your container has bash installed).

cilphex
  • 6,006
  • 6
  • 34
  • 44