Skip to content

Instantly share code, notes, and snippets.

@maximd
Last active April 1, 2016 15:25
Show Gist options
  • Save maximd/7aa78d16fe1a97b313a1024072980f85 to your computer and use it in GitHub Desktop.
Save maximd/7aa78d16fe1a97b313a1024072980f85 to your computer and use it in GitHub Desktop.
docker with docker-machine on centos 6
# Author: Maxim Doucet
# Date: 2016-04-01
# docker machine and docker client to run docker in virtualbox with centos 6
###############################################################################
# install it in $HOME
mkdir -p ~/local/docker
# download docker machine
curl -L https://github.com/docker/machine/releases/download/v0.6.0/docker-machine-`uname -s`-`uname -m` > ~/local/docker/docker-machine-0.6.0
# get the sha256sum at https://github.com/docker/machine/releases
# download docker client (see https://github.com/docker/docker/releases)
curl -L https://get.docker.com/builds/Linux/x86_64/docker-1.10.3 > ~/local/docker/docker-1.10.3
curl -L https://get.docker.com/builds/Linux/x86_64/docker-1.10.3.sha256 > ~/local/docker/docker-1.10.3.sha256
# make the files executable
chmod a+x ~/local/docker/docker!(*sha256*)
# create symbolic links in ~/bin
pushd ~/bin
ln -fs ../local/docker/docker-1.10.3 docker
ln -fs ../local/docker/docker-machine-0.6.0 docker-machine
# prepare a place to install bash completion in $HOME
cat << EOF >> ~/.config/bash_completion
for f in ~/.config/bash_completion.d/* ; do
source "$f"
done
EOF
mkdir ~/.config/bash_completion.d
# download docker machine bash completion
# see https://docs.docker.com/machine/completion/
files=(docker-machine docker-machine-wrapper docker-machine-prompt)
for f in "${files[@]}"; do
curl -L https://raw.githubusercontent.com/docker/machine/v$(docker-machine --version | tr -ds ',' ' ' | awk 'NR==1{print $(3)}')/contrib/completion/bash/$f.bash > ~/.config/bash_completion.d/$f
done
# download docker client bash completion
curl -XGET https://raw.githubusercontent.com/docker/docker/master/contrib/completion/bash/docker > ~/.config/bash_completion.d/docker
###############################################################################
# use docker with docker machine
# setup a docker host in virtuabox
# by following https://docs.docker.com/machine/get-started/
docker-machine create --driver virtualbox --virtualbox-cpu-count 2 --virtualbox-memory 2048 default
# stop it with
docker-machine stop
# start it with
docker-machine start
# initialize docker with
eval "$(docker-machine env default)"
# test by running echo in a lightweight container (https://hub.docker.com/_/alpine/)
docker run alpine echo hello world
# check what's the docker host's IP address
docker-machine ip default
# we can have a nginx server running and test it on port 8000 via
docker run -p 8000:80 nginx
# or a daemonized version
docker run -d -p 8000:80 nginx
# update docker-machine virtualbox
docker-machine upgrade
# list and update a docker image
docker images
docker pull alpine
###############################################################################
# docker-machine aliases
RED='\[\e[0;31m\]'
NC='\[\e[0m\]' # No Color
alias docker-start='docker-machine start default ; PS1_ORIG_DM="${PS1}" ; PS1="${RED}\$(__docker_machine_ps1 docker-%s)${NC} ${PS1}" ; eval "$(docker-machine env default)" ; echo "docker-machine ip: $(docker-machine ip)"'
alias docker-stop='docker-machine stop default ; unset DOCKER_TLS_VERIFY DOCKER_HOST DOCKER_CERT_PATH DOCKER_MACHINE_NAME ; PS1="${PS1_ORIG_DM}"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment