Hosting - kristinedomingo/cs373-idb GitHub Wiki

Carina by Rackspace

This website was hosted using Carina by Rackspace, a native container environment. An engineer from Rackspace, Everett Toews, gave a presentation and tutorial on how to deploy a Python web application on Carina using Docker Compose. The tutorial provided most of the information needed to set up sweetmusic.me.

Creating and Connecting to a Cluster

  1. Go to the Carina website and create an account. On the Clusters page, click on "Add Cluster", and name it appropriately.
  2. The newly created cluster will provide a .zip file of its credentials. Download these credentials and unzip the contents into a folder (for example, Downloads/mycluster.
  3. Run the following commands:
    $ cd Downloads/mycluster
    $ mkdir -p $HOME/bin
    $ mv docker-1.9.0 $HOME/bin/docker
    $ chmod u+x $HOME/bin/docker
    $ export PATH=$HOME/bin:$PATH
    $ if [ -f ~/.bash_profile ]; then echo 'export PATH=$HOME/bin:$PATH' >> $HOME/.bash_profile; fi
    $ source docker.env
  1. Now, docker info should display the cluster information.
  2. To reconnect to the cluster, just navigate to the credentials folder and re-run source docker.env.

Building and Pushing the Application Images

  1. First, source the environment file for the application's cluster (source docker.env).
  2. Log in to Docker Hub (docker login).
  3. Build and push each image the application contains. Run the following commands, where {DOCKER_HUB_USERNAME} is the username for Docker Hub, {IMAGE_NAME_APP} is the name of the image, and {SERVICE_NAME} is the name of the service.
    docker build -t ${DOCKER_HUB_USERNAME}/${IMAGE_NAME_APP} {SERVICE_NAME}
    docker push ${DOCKER_HUB_USERNAME}/${IMAGE_NAME_APP}

Deploying the Application to Carina

  1. Before deploying the application, the docker-compose-prod.yml file should be configured to the application. Sweetmusic.me uses this production file.
  2. Once the images are built and pushed, and the production file is configured, run
    docker-compose --file docker-compose-prod.yml up -d

Automating the Build, Push, and Deploy Process

To avoid having to repeat all of the steps above every time sweetmusic.me had to be updated, the makefile for this project condenses all of the steps into the commands make docker-build and make docker-push. The relevant parts of the makefile are shown below:

    IMAGE_NAME_APP := sweetmusic_app
    IMAGE_NAME_LB := sweetmusic_lb
    DOCKER_HUB_USERNAME := swetifygroupmembers

    docker-build:
        @if [ -z "$$CONTINUE" ]; then \
            read -r -p "Have you sourced the docker.env file for our Carina cluster? (y/n): " CONTINUE; \
        fi ; \
        [ $$CONTINUE = "y" ] || [ $$CONTINUE = "Y" ] || (echo "Exiting."; exit 1;)
        @echo "Building the images..."
        docker login

        docker build -t ${DOCKER_HUB_USERNAME}/${IMAGE_NAME_APP} app
        docker push ${DOCKER_HUB_USERNAME}/${IMAGE_NAME_APP}

        docker build -t ${DOCKER_HUB_USERNAME}/${IMAGE_NAME_LB} lb
        docker push ${DOCKER_HUB_USERNAME}/${IMAGE_NAME_LB}

    docker-push:
         docker-compose --file docker-compose-prod.yml up -d

Troubleshooting

An unable to find a port with node 80 available error might occur when trying to push to the Carina cluster. This happens when there is an image from a Docker Hub repository is already on the cluster, and docker-push is trying to push an image from a different Docker Hub repository. To remove images from the cluster:

  1. Run docker-compose ps -a to see a list of images on the cluster.
  2. Run docker rm {ID} for each image to be removed, where {ID} is the image ID (reference the output from above).
  3. Run docker-push again to push the images.