Monday, January 12, 2015

Using Docker on Mac OS X

Installation


Docker is the newest iteration of linux containers - self-contained,  chroot-like minature VM.  Docker is an OSS product, produced by https://www.docker.com/ .

Installing it on Mac OS X requires installing VirtualBox, Docker and boot2docker. I used Home Brew package manager to install (I had VirtualBox installed already)

brew update
brew install docker
brew install boot2docker
boot2docker init
boot2docker up

The up command returns three environment variables DOCKER_CERT_PATH, DOCKER_TLS_VERIFY and DOCKER_HOST that need to be exported to your environment.

After this, docker is installed and ready to use.

Find a list of docker images with the command

docker images

Initially there will be no images. When using docker to create a new image, the actual image is downloaded and installed. After that first install, that image will be available for future use.

Creating first Docker Container


Let's create a CentOS container.

docker run --rm -i -t centos /bin/bash


That's it. All the needed packages will be downloaded and installed
You will be popped into a root prompt of the container - essentially a fully featured CentOS system with its own filesystem, network stack, IP, etc.

--rm means it will destroyed on exit
-i means interactive (because we are running /bin/bash inside the centos image)
 
Compute to heart's content. Exit with Control-D and the container is destroyed.



Creating a non-transient docker image


docker run -i -t centos /bin/bash

Make changes to this container (create files) and exit

Now, the command "docker ps -a" should show a new container.
You can save the state of this container aas a new image using
docker commit CONTAINERID NAME
after which "docker images" should show the new image listed with NAME.

Dockerfiles


Dockerfiles are bootstrap files that can be associated with an image. It can be used to install new packages, mount filesystems, execute commands, etc. Sample docker files are shared by the OSS community on hub.docker.com


No comments:

Post a Comment