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
pwd
/home/username/dockercloud-hello-world
-v /var/run/docker.sock:/var/run/docker.sock
option.To make the current directory available to the container, use the -v "PWD"
option to mount it as a volume and the -w="PWD:PWD" \
docker/compose:1.24.0 up
docker run
command 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
The 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-compose
alias to your shell configuration file, e.g..bashrc
.echo alias docker-compose="'"'docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "PWD" \
-w="$PWD" \
docker/compose:1.24.0'"'" >> ~/.bashrc - Reload the Bash configuration.
source ~/.bashrc
- Change back to the sample directory if you aren't already there.
cd ~/dockercloud-hello-world
- Run the sample code using the new
docker-compose
alias.docker-compose up
You should be able to view the "Hello World" message at your instance's external IP address.
Source: https://cloud.google.com/community/tutorials/docker-compose-on-container-optimized-os