Skip to content

Instantly share code, notes, and snippets.

@mplewis
Last active January 3, 2016 10:09
Show Gist options
  • Save mplewis/8447487 to your computer and use it in GitHub Desktop.
Save mplewis/8447487 to your computer and use it in GitHub Desktop.
Deploy @thenewtricks hello-world-nodejs with Docker
#!/bin/sh
# Verbose mode
set -o verbose
# Get the repo to working condition
cd ../docker-hello-world-nodejs
git checkout -f master
git pull
# Get the old container ID
export OLD_CONTAINER_ID=$(docker ps | grep 'thenewtricks/hello-world-nodejs' | awk '{print $1}')
# Build the up-to-date image
docker build -q -rm -t thenewtricks/hello-world-nodejs .
# Stop the old container
if [ -z "$OLD_CONTAINER_ID" ]; then
echo "No old container found."
else
echo "Stopping and removing old container with ID $OLD_CONTAINER_ID"
docker stop $OLD_CONTAINER_ID
docker rm $OLD_CONTAINER_ID
fi
# Create a container for the new image and run it
docker run -p 3717:3717 -d thenewtricks/hello-world-nodejs:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment