Skip to content

Instantly share code, notes, and snippets.

@revolunet
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revolunet/733fe08276c8cd5f2dbe to your computer and use it in GitHub Desktop.
Save revolunet/733fe08276c8cd5f2dbe to your computer and use it in GitHub Desktop.
Docker OSX setup memo

Setup docker for OSX

Note: use phusion/baseimage instead of ubuntu

⚠️ The default boot2docker doesn't allow local mounts on OSX, seee workaround below !

Install boot2docker

boot2docker init
boot2docker start
export DOCKER_HOST=tcp://$(boot2docker ip 2>/dev/null):2375
# warn: if you have multiple open shells, make sure to export the DOCKER_HOST variable in every one as the docker command use it to communicate with the minimal linux VM.
# to get the VM IP
boot2docker ip

Run a sample image

# download an image from the hub and run a command into it
docker run ubuntu echo "hello world"

# get an interactive shell to the image
docker run -t -i ubuntu /bin/bash

# run a daemon. this returns a process SHA
docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"

# check processes
docker ps
docker logs [-f] [SHA]
docker stop [SHA]

Run

  • -d : run detached
  • -P : expose all open ports
  • -p 6000:5000 : expose container port 6000 to local port 5000
  • --name webapp : explicitly name this container

Images

  • docker search django : search images
  • docker pull django : fetch locally

Update an existing image

Run an interactive shell (-t -i), then exit, then commit the changes :

docker commit -m 'commit message' [SHA] username/newimage:v2

Create a new image from scratch

Create a new folder with a Dockerfile (full reference)

example file :

FROM phusion/baseimage
MAINTAINER Julien Bouquillon <julien@revolunet.com>
RUN apt-get -qq update
RUN apt-get -qqy install mpg123 vlc

Build the new image : docker build -t="username/mydebian:v1" .

OSX mounts workaround

There is a workaround that enables mounting anything in /Users :

Now you can use -v to mount local folders to your containers !

(More details in this blogpost : https://medium.com/boot2docker-lightweight-linux-for-docker/boot2docker-together-with-virtualbox-guest-additions-da1e3ab2465c)

Cleanup and delete stopped containers

docker ps -a | grep "Exit" | awk '{print $1}' | while read -r id ; do
  docker rm $id
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment