Skip to content

Instantly share code, notes, and snippets.

@ryanmaclean
Last active July 13, 2017 10:11
Show Gist options
  • Save ryanmaclean/e49cbc421c88815aef88 to your computer and use it in GitHub Desktop.
Save ryanmaclean/e49cbc421c88815aef88 to your computer and use it in GitHub Desktop.
Mac OSX Yosemite and AWS ECS Docker Setup with Command Cheat Sheet
########################################################
### Getting Docker on a Macintosh 10.10 computer & ###
### Commands to use for administration of Docker ###
### "ubuntu" is used as a variable name here ###
### for a generic instance name. ###
########################################################
### Most of the commands are cribbed from "Docker ###
### up and Running" ###
### http://shop.oreilly.com/product/0636920036142.do ###
### The rest are things related to personal testing ###
########################################################
########################################################
# First, some housekeeping:
# For the hackintosh users out there...
# Make sure VT-x is turned on. This is commonly
# referred to as "virtualization support" in (u)EFI
# "Real" Mac owners, you'll be fine if you're able to run
# Mavericks and up.
# Also, just in case you don't have
# Homebrew and Homebrew Cask installed -
# uncomment the following lines
#ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
## Accept OSX Dev Tools license
#sudo xcodebuild -license
## Install Homebrew Cask
#brew install caskroom/cask/brew-cask
########################################################
# You can get docker running on Macos in two ways
# The "easy" way with Kitematic, or the "manual"
# way with Boot2Docker and Virtualbox
# Kitematic way
# Install Kitematic with Brew Cask
brew cask install kitematic
# Virtualbox Kitematic networking fix
# https://github.com/kitematic/kitematic/issues/386
sudo route -nv add -net 192.168.99 -interface vboxnet0
# Run the Kitematic setup (enter admin pass)
open ~/Applications/Kitematic\ \(Beta\).app
# Kitematic on Mac - fix Docker CLI
eval "$(docker-machine env dev)"
# Manutal way with Boot2Docker and Virtualbox
# Install Virtualbox
brew cask install virtualbox
# Install Boot2Docker
brew cask install boot2docker
# Docker Commands
# Start Docker daemon
sudo docker -d
# Get Docker version
docker version
# Get system info
docker info
# Pull a Docker image
docker pull ubuntu
# Pull a specific version of a Docker image
docker pull ubuntu@sha256:6f21...8563
# Create Docker container and name it "ubuntu"
docker create --name="ubuntu" ubuntu
# Run a Docker image, run a command, then delete on exit
docker run --rm -ti ubuntu /bin/bash
# Run a command in an existing container
docker exec -t -i ubuntu /bin/bash
# Pause a Docker container
docker pause ubuntu
# Unpause a Docker container
docker unpause ubuntu
# Stop a Docker container
docker stop ubuntu
# Start a Docker container
docker start ubuntu
# Restart a Docker container
docker restart ubuntu
# Inspect a container
docker inspect ubuntu
# Remove all containers
docker rm $(docker ps -a q)
# Remove all images
docker rmi $(docker images -q -)
# Display resource utilization for a container
docker stats ubuntu
# Search for an image on Docker hub
docker search ubuntu
# Install a container package on a Docker host (example, nsenter)
docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter
# Get logs for container
docker logs ubuntu
# Tail container logs
docker logs -f ubuntu
# Show commands running in a container
docker top ubuntu
# Run Google Cadvisor
# Note: in Docker up and Running, it was mentioned that on
# RHEL and CentOS you'd also need to add
# --volume=/cgroup:/cgroup
# as a parameter
docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --publish=8080:8080 --detach=true --name=cadvisor google/cadvisor:latest
# Open Safari to this page
open /Applications/Safari.app http://192.168.99.101:8080/containers/
# Run Docker container as UID 5000
docker run -u 5000 ubuntu
# Install pstree to look at Docker process tree
brew install pstree
# Examine Docker processes in tree view
pstree `pidof docker`
# Kill a process
docker kill 987987
# Get history for an image
docker history ubuntu:latest
# Diff a container; A for Add, C for Change
docker diff d539fcb1700a
# Setup a Docker container cluster
docker pull swarm
docker run --rm swarm create
# This returns a token that you'll use in the next step
a326fd338c8c86c533fd21d8dce4b4d6
# Register a Docker host with cluster
docker run -d swarm join --addr=192.168.99.101:2375 token://a326fd338c8c86c533fd21d8dce4b4d6
# This returns the full hash of the container:
9106c63fab5ff42b7c2e624a46ce53f727953a9e2935c558f888681ae6ce5433
# Deploy the Swarm manager
docker run -d -p 9999:2375 swarm manager token://a326fd338c8c86c533fd21d8dce4b4d6
# List all nodes in the cluster
docker run --rm swarm list token://a326fd338c8c86c533fd21d8dce4b4d6
# Create Docker host alias for cluster deployment
echo $DOCKER_HOST; unset DOCKER_HOST
# Returned tcp://192.168.99.101:2376
echo $DOCKER_TLS_VERIFY; unset DOCKER_TLS_VERIFY
# Returned "1" - previously enabled
echo $DOCKER_TLS; unset DOCKER_TLS
# Returned an empty string
echo $DOCKER_CERT_PATH; unset DOCKER_CERT_PATH
# Returned /Users/strang/.docker/machine/machines/dev
export DOCKER_HOST="tcp://192.168.99.101:9999"((("docker", "info")))
# Install New Relic Centurion deployment tool
# https://github.com/newrelic/centurion
# Note that you might not want sudo on systems
# other than OSX
brew install ruby rbenv ruby-build
sudo gem install centurion bundler
bundle install
# Add Centurion to our path just in case
gempath=`gem environment | grep "INSTALLATION DIRECTORY" | awk '{print $4}'`
export PATH=$gempath/bin:$PATH
# Test command for Centurion
centurion --help
# This should return the Centurion help
# Create local Nginx scaffolding
mkdir nginx
cd nginx
centurionize -p nginx
# Have a look at the config it generated and uncomment the #host
nano config/centurion/nginx.rake
# Deploy a staging environment with Centurion
centurion -p nginx -e staging -a rolling_deploy
### Create amazon container cluster
aws ecs create-cluster --cluster-name testing
### List containers running in a cluster
aws ecs list-container-instances --cluster testing
### Delete a cluster
aws ecs delete-cluster --cluster testing
### Using the ID that is spit out from the previous commands
### get details about a container
aws ecs describe-container-instances --cluster testing --container-instances 323424-2424234-234234
### Deploy a task based on JSON to a cluster
aws ecs run-task --cluster testing --task-definition starwars-telnet:1 --count 1
### Check status of a task deployed to container service
aws ecs describe-tasks --cluster testing --task 345-345354-5345-345354
### Stop a task
aws ecs stop-task --cluster testing --task 345-2324243-23423-234234
### Sample AWS ECS App
{
"family": "console-sample-app",
"volumes": [
{
"name": "my-vol",
"host": {}
}
],
"containerDefinitions": [
{
"environment": [],
"name": "simple-app",
"image": "ryanmaclean/ansible",
"cpu": 10,
"memory": 500,
"portMappings": [
{
"containerPort": 80,
"hostPort": 80
}
],
"mountPoints": [
{
"sourceVolume": "my-vol",
"containerPath": "/var/www/my-vol"
}
],
"entryPoint": [
"/usr/sbin/apache2",
"-D",
"FOREGROUND"
],
"essential": true
},
{
"name": "busybox",
"image": "busybox",
"cpu": 10,
"memory": 500,
"volumesFrom": [
{
"sourceContainer": "simple-app"
}
],
"entryPoint": [
"sh",
"-c"
],
"command": [
"/bin/sh -c \"while true; do /bin/date > /var/www/my-vol/date; sleep 1; done\""
],
"essential": false
}
]
}
### Register a command definition
aws ecs register-task-definition --cli-input-json file://simple-app-task-def.json
### Run a defined task
aws ecs run-task --task-definition console-sample-app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment