It is recommended to deploy docker-compose containers on a Container-Optimized OS which is Google’s recommended OS for hosting and running containers on GCP. Container-Optimized OS is free to use on GCE. Container Optimized OS has the following features:
- Optimized for Containers
- Built to Scale
- Minimal OS, Maximum Security
- Open Source and maintained by Google
Setting up the virtual machine
Create a new Compute Engine instance using the Container-Optimized OS stable image.
- Open the Cloud Console.
- Create a new Compute Engine instance.
- Select the desired Zone, such as “us-central1-f”.
- Select the desired Machine type, such as “micro” (f1-micro).
- Change the Boot disk to “Container-Optimized OS stable”.
- Check the box to allow HTTP traffic in the Firewall section.
- Click the Create button to create the Compute Engine instance.
SSH into the COOS and Clone your repository
(uname -s)- pwd
-v /var/run/docker.sock:/var/run/docker.sockoption.To make the current directory available to the container, use the
-v "PWD"option to mount it as a volume and the
docker runcommand still running, open the Cloud Console instances page. Click the link to your instance's External IP address.You should see a "Hello World" message appear.
Making an alias to Docker Compose
docker run ... docker/compose:1.24.0 up command is equivalent to running the
docker-compose up command on systems where Docker Compose is installed by the usual method. So that you don't have to remember or type this long command, create an alias for it.
- Add a
docker-composealias to your shell configuration file, e.g.
echo alias docker-compose="'"'docker run --rm
docker/compose:1.24.0'"'" >> ~/.bashrc
- Reload the Bash configuration.
- Change back to the sample directory if you aren't already there.
- Run the sample code using the new
docker-compose upYou should be able to view the "Hello World" message at your instance's external IP address.