Running docker-compose in Google Cloud

I have a docker container that works fine on my machine if I run it with docker-compose but it does not work well with running it using docker run , However, when I create a container to put it on Google Cloud, the Google Cloud SDK is not using docker-compose, here is how I fixed this problem.

First, you need to resize the hard disk. The hard disk that is being used by your instance is probably not big enough. Here I increase mine to 30GB. The hard disk name is the same as the instance name (do not add a new disk, it will not increase your root partition):

gcloud compute disks resize example-disk — size 250

Add your ssh public key to your instance so that you can ssh into your account from your computer.

After increasing the disk space, copy all your files into the server using scp.

scp * <external_ip_address>:~

Then ssh into your instance and make sure all your files are there.

Now you need to run docker-compose but it doesn’t exist in Google Cloud Container OS. To do that you need to first create a docker-compose container:

docker run docker/compose:1.13.0 version

and then run this command:

docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$PWD:$PWD" \
-w="$PWD" \
docker/compose:1.13.0 up

I copied these lines from this tutorial. But, I changed the second command because I kept getting an error saying “can not make directory /rootfs, filesystem is read-only”. That’s why I removed rootfs from my commands.

After running this command, your docker container should start and should work fine.

Comments