Skip to content

Instantly share code, notes, and snippets.

@DevoKun
Last active August 29, 2015 14:10
Show Gist options
  • Save DevoKun/023a2a5e6e61cf3c354f to your computer and use it in GitHub Desktop.
Save DevoKun/023a2a5e6e61cf3c354f to your computer and use it in GitHub Desktop.
Operate Boot2Docker on MacOS X

Download and Install the latest release

Create the Virtual Machine in VirtualBox

boot2docker init

Launch the Virtual Machine and the Docker daemon

boot2docker start

Set DOCKER_HOST

  • The boot2docker start command will return an environment variable to be set.
export DOCKER_HOST=tcp://192.168.59.103:2375

Test the running daemon with a simple hello-world

  • This container is included with boot2docker
docker run hello-world

Test the running daemon with Ubuntu

docker pull ubuntu:14.04.1
docker run -i -t ubuntu:14.04.1 /bin/bash

Share directories on MacOS X with the Docker VM so it can share directories with the Docker containers

Gotcha

  • Assuming you are in your home directory on MacOS X (/Users/$USERNAME), you can not directory share a directory with the Docker container.
  • The Docker container is running on the Boot2Docker VM, which has different directories from MacOS X.
docker run -i -t -v $(pwd)/Documents:/mnt/Documents ubuntu:14.04.1 /bin/bash
ls /mnt/Documents
exit

Pre-Boot2Docker 1.3

Follow these instructions for creating a custom boot2docker.iso:

Post-Boot2Docker 1.3

Stop the Virtual Machine

boot2docker stop

Upgrade boot2docker

Download and install the latest release

Upgrade the Virtual Machine

boot2docker stop
boot2docker download
boot2docker start

Accessing exposed ports on boot2docker

  • Boot2docker is a VM running the docker daemon.
  • When you expose a running port, the port is running on the boot2docker VM, not on the parent host
docker run -p 8080:8080
  • To access the exposed port, find the IP of boot2docker and then connect to the shared port:
boot2docker ip
DOCKERIP=$(boot2docker ip 2>/dev/null)

Fig

Install fig

  • Brew will install fig 0.5.2 (brew install fig), which is NOT compatible with Docker 1.3+.
  • Install fig 1.0 or newer as outline on the fig website
curl -L https://github.com/docker/fig/releases/download/1.0.1/fig-`uname -s`-`uname -m` > /usr/local/bin/fig; chmod +x /usr/local/bin/fig

Illigal Instruction: 4

brew install python
easy_install pip
pip install fig

Example from the Fig website

mkdir figtest
cd figtest
cat << EOF > app.py
from flask import Flask
from redis import Redis
import os
app = Flask(__name__)
redis = Redis(host='redis', port=6379)

@app.route('/')
def hello():
    redis.incr('hits')
    return 'Hello World! I have been seen %s times.' % redis.get('hits')

if __name__ == "__main__":
    app.run(host="0.0.0.0", debug=True)
EOF

cat << EOF > requirements.txt
flask
redis
EOF

cat << EOF > Dockerfile
FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
EOF

cat << EOF > fig.yml
web:
  build: .
  command: python app.py
  ports:
   - "5000:5000"
  volumes:
   - .:/code
  links:
   - redis
redis:
  image: redis
EOF

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