Unfortunately OSX doesn’t have the necessary kernel features to run the docker daemon natively. But, yet ‘Boot2Docker’ is a all-in-one bundle that installs docker client for OSX. It also includes virtual box and a virtual machine all geared up for running the docker daemon.
Once you have installed the Boot2Docker bundle. Starting ‘boot2docker’ will spin up the virtual machine and the docker daemon. Docker is now ready to receive commands from the client (your OSX machine).
Note: Once the boot2docker console has started running, you can minimise it. This terminal is for the virtual machine running the docker daemon. Just think of it as some far-away server that receives commands from your OSX machine.
In a new terminal window, configure the docker client (which does run natively on OSX). First figure out what ip address your docker daemon is running on:
$ boot2docker ip
Now add the following configuration to your environment:
$vim .bash_profile export DOCKER_TLS_VERIFY=1 export DOCKER_HOST=tcp://192.168.59.103:2376 #This should be the IP address from the boot2docker ip command above. The default docker port is 2376 export DOCKER_CERT_PATH=/<usr dir>/.boot2docker/certs/boot2docker-vm $source .bash_profile
Finally you are all good to start ‘dockerizing’ some applications:
Other documents related to installing and getting started with docker:
Docker Development lifecycle
Here I was aiming to replace vagrant and chef as a way of setting up development images. I wanted to be able to have each of my projects seperated into their own container.
To build and run your application, create a Dockerfile that uses:
- ‘COPY’ commands to copy your source/application from your development machine into the container.
- ‘RUN’ commands to install and build your source/application within the container.
- ‘CMD’ instructions to fire up your application after it the container builds it.
Then build your image by executing your Dockerfile use (this copys source from your dev machine into the container, runs the build scripts and finally executes the resulting product):
$docker build -t <name of image> .
Once built, an instance of an image (called container) is created to run your application. The following creates a container locally:
$docker run --name <name of container> -d -p 80:80 <name of image>
- -d runs the container in ‘detached’ mode. Containers running in the background are perfect for long running stuff like web apps
- -p 80:80 Publishes the container port (80) to the host port (80), It takes the format of hostPort:containerPort.
On an OSX development machine, point your browser at the IP address returned by boot2docker ip to see your running site. (i.e. in this example 192.168.59.103)
Images can be rebuilt by running docker build again. However, you will need to remove a running container before you can use the same name again.
$docker rm -f <name of container>
- -f Forces the container to stop before it is removed.
All current containers can be listed with:
$docker ps -a
All the locally available images can be listed with:
Other documents on developing with docker:
Piecing it all together
- Define how to build and run your application in a Dockerfile.
- Edit source code normally would on your OSX machine.
- Build an image from your source code changes (docker build). This is surprisingly fast!
- Run your image as a container, and view the results on the boot2docker ip address.
- Rinse and repeat (just remember to delete the old container so that you can re-use the name).
Deploying ‘dockererized’ applications is a little more involved, will cover this (and how to prepare a server with chef) in a follow up soon.
Hi! Subconsciously you already know this, but let's make it obvious. Hopefully this article was helpful. You might also find yourself following a link to Amazon to learn more about parts or equipment. If you end up placing an order, I make a couple of dollarydoos. We aren't talking a rapper lifestyle of supercars and yachts, but it does help pay for the stuff you see here. So to everyone that supports this place - thank you.