Skip to content

james-google/container-vm-guestbook-redis-python

 
 

Repository files navigation

Container VM Guestbook

This is a sample on how to use container VMs for a simple guestbook. You can read more about containers on GCE here.

There are 2 containers that get deployed into one VM:

  • A Redis database. This is uses the dockerfile/redis container image.
  • An simple python application (based on Flask) that implements the guestbook. The source is included at the root of this repo and is pushed to google/guestbook-python-redis on the Docker Index.

Launching

To launch simply have gcloud compute configured (see the Cloud SDK) with a GCE enabled project and your credentials. There is no need to have Docker installed on your workstation/development machine.

Either run the start-containers.sh shell script or run the following commands:

VM_NAME=container-vm-guestbook
gcloud compute firewalls create ${VM_NAME}-www --allow tcp:80 --target-tags ${VM_NAME}

gcloud compute instances create ${VM_NAME} \
  --tags ${VM_NAME} \
  --zone us-central1-a  --machine-type n1-standard-1 \
  --image https://www.googleapis.com/compute/v1/projects/google-containers/global/images/container-vm-v20140624 \
  --metadata-from-file google-container-manifest=manifest.yaml

This will create a new VM called containervm-guestbook running the 2 containers described above. We also open up the firewall to just this VM so that you can reach the web server running on it. The containers that are running in the VM are specified in manifest.yaml. It may take a while to get up and running as the container image must be downloaded from the docker registry.

Just hit the public IP of the VM with your web browser to access the guest book.

Restarting the containers

If you want to change the manifest and reload it, the easiest thing to do is to upload a new manifest and restart the VM hosting the containers.

You can run the restart-containers.sh script or run the following commands:

gcloud compute instances add-metadata --zone us-central1-a ${VM_NAME} \
  --metadata-from-file google-container-manifest=manifest.yaml

gcloud compute instances reset --zone us-central1-a ${VM_NAME}

Cleaning up

To clean up the VM, simply run stop-containers.sh. This will delete the VM and its root disk. Any data on the VM will be lost!

Or run the following commands:

gcloud compute firewalls delete --quiet ${VM_NAME}-www

gcloud compute instances delete --quiet --zone=us-central1-a ${VM_NAME}

Modifying the application

  1. Have Docker installed on a development workstation. You can use a GCE instance for this. See instructions here.
  2. Create an account on index.docker.io and run docker login.
  3. Build your application with docker build -t <username>/guestbook-python-redis ..
  4. Push your application with docker push <username>/guestbook-python-redis.
  5. Modify manifest.yaml to refer to your new application.
  6. Start up a new VM with start-containers.sh or reload you rexisting one with restart-containers.sh.

About

A simple guestbook example for Container VMs on GCE. Uses Redis and Python/Flask.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 67.6%
  • Python 32.4%