Skip to content

Instantly share code, notes, and snippets.

@ricog
Created October 8, 2014 17:20
Show Gist options
  • Save ricog/e5f468f24a475f89e9cf to your computer and use it in GitHub Desktop.
Save ricog/e5f468f24a475f89e9cf to your computer and use it in GitHub Desktop.
Intro to Docker on OSX

Intro to Docker

Installing Docker on OSX (using boot2docker)

Look at Docker Installation or if you already have VirtualBox and Homebrew installed:

`brew update && brew install docker`

Running the Docker VM

Docker runs in a Linux VM on OSX. A Docker client runs on your host machine to control Docker containers in the VM. The boot2docker command controls that VM and provides information about it. You can issue the command without any arguments to see a list of available sub-commands.

boot2docker

You can start the VM and set the appropriate DOCKER_HOST environment variable with:

boot2docker up && $(boot2docker shellinit)

What are Docker Containers?

Docker extends the functionality of lxc (linux containers). The improvements are best described here: Stackoverflow: What does Docker add to just plain LXC

Using Docker Containers

Below are some example commands.

See what sub-commands are available.

docker

Get help about the run command.

docker run --help

Run an Ubuntu container.

The default command for this container is bash. Once in there, run top to see what is running. Type exit and hit enter to quit the container.

docker run -it --rm ubuntu

Run a specific command in a container.

This will output the Ubuntu release information. When a container's command is finished it will stop automatically.

docker run -it --rm ubuntu cat /etc/lsb-release

Build an image (from a Dockerfile).

mkdir docker-test
cd docker-test
echo 'FROM tutum/lamp:latest' > Dockerfile 
docker build -t my-image .
cd ..

Run your new image in a container.

docker run -d -p 8080:80 --name my-container my-image

View your handywork.

Find your VM ip with:

boot2docker ip

Now use this IP to access your container in a browser. Something like:

http://192.168.59.103:8080

Stop your container.

docker stop	my-container
docker rm my-container

or

docker rm -f my-container

Learn more.

Docker User Guide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment