Mac Docker 1.12.0-rc3-beta18 native client and insecure registry

A while back I set up a local Docker Registry to share images between different machines, and configured it as an ‘insecure registry’ since it’s just for testing. With the latest native Docker engine for Mac OS, I was having difficulty pushing to the Registry, it was just fail with a cryptic message:

$ docker push 192.168.1.66:5000/rpi-mongodb

The push refers to a repository [192.168.1.66:5000/rpi-mongodb]

Get https://192.168.1.66:5000/v1/_ping: http: server gave HTTP response to HTTPS client

I noticed in the Docker menu from the menu bar that there’s a Insecure Registries section under Preferences, Advanced Options. Adding the IP and port of my Registry there fixed my problem, now I can push:

$ docker push 192.168.1.66:5000/rpi-mongodb:latest

The push refers to a repository [192.168.1.66:5000/rpi-mongodb]

3d4f4a09f67b: Pushed 

fc91d495516f: Pushed 

5f70bf18a086: Pushed 

532820a7256b: Pushed 

ed62ae893def: Pushed 

994d5442545b: Pushed 

f097d343f850: Pushed 

latest: digest: sha256:c71c6743924243d6117050a1b5b95adf4effee7c9059315c0bfe500f67e0d16b size: 260

Managing Docker containers with Shipyard

There’s plenty of things that amaze me about Docker, but one of the things I find interesting is the number of available images with all sorts of stuff preconfigured and ready to spin up, including Docker management related tools like Shipyard that also run within Docker containers themselves.

Installing couldn’t be simpler, just pull down a script and run it, and it pulls down a number of images and spins them up:

curl -sSL https://shipyard-project.com/deploy | bash -s

Within a few seconds Shipyard is up and running, and after logging on, you get the snappy looking dashboard:

Now, off to do a bit more studying to configure a spin up a Swarm cluster 🙂

Apache httpd in a Docker container

I have a ‘getting started‘ post on Docker already, so I thought it would be useful to pull together some of the simplest possible examples of building and running Docker containers, as real examples.

On the Docker Hub there’s many prebuilt images already. As a quick example, let’s use the Apache Httpd image and build a container that runs httpd and serves an example webpage.

This is pretty much the instructions that are on the httpd image page, so no surprises here.

In a new folder, create a Dockerfile:

FROM httpd:2.4
COPY ./public-html/ /usr/local/apache2/htdocs/

Create an index.html file in public-html and put some hello world content in it.

Next, from a Docker Quickstart Terminal, cd into the folder when you created the Dockerfile and public-html, and build your image:

docker build -t imagename .

 
Now to start up a container based on your image called imagename (name it whatever you like), and expose port 80 on the container to port 80 to the outside world:

docker run -it -p 80:80 imagename

Now point a browser at the IP of your docker machine (displayed when Docker Quickstart starts up), and success, you should see your html being served from apache in your container!

If you’re on Windows, the equivalent to capture the tty output is:

winpty docker run -it -p 80:80 imagename

Docker basics in a nutshell

I have a number of posts from my playing around with Docker so far. I’ve seen a number of posts from people asking how they should get started with Docker. There’s a number of getting started guides that will get you up and running. Try the Getting Started tutorials on the Docker site.

I’m not going to attempt to re-write my own version of other tutorials as they are good already. Instead, I’m going to distill down a few core steps as a quick reference and a quick example. If you’ve no idea what Containerization is about, this page is a good overview.

Assuming first if you’re on Mac or Windows you’ve already installed the Docker Toolbox. If not, head over here and follow the instructions.

In a nutshell:

  • images are read-only definitions used to create a container (they describe the content of a container, starting with a base image, at the very least a base Linux OS)
  • You can browse shared images at Docker Hub (or host your own hub)
  • images can be used as the starting point and extended to create other images
  • a container is an instance of an image that can start, pause, stop

Start the Quickstart Terminal.

Let’s pull an image (busybox) and start it up:

  • docker pull busybox

Now let’s run a container based on this image, run it interactively (-i) capturing the tty (-t) and execute a shell (the hex value is the id of the image):

  • docker run -it c51f86c28340 sh

On a reasonably recent machine you’ll probably see the sh prompt appear in a second or less. If you exit the shell, your container will also terminate because it’s not running anything (by exiting the shell you terminated the command you asked the container to run).

You can see currently running containers with ‘docker ps’ and list all containers included recently terminated with ‘docker ps -a’:

Let’s start it up the same container again in interactive mode: ‘docker start -i 9fd9f0402821′ :

Each time we start it up, you should notice it starts pretty quick, in 1 second or less.

Containerization vs Virtualization

If you’ve ever installed a guest OS in a virtual machine using virtualization software like VirtualBox, VMWare or Parallels, you should now be noticing a major difference between containerization and virtualization. How did that container boot so fast??!!

The difference between these two approaches is that virtualization allows sharing of the platform hardware, so multiple guest OSes can be installed on the same hardware. Containers on the other hand allow sharing of the operating system – each container shares common libraries and resources from the underlying Linux OS. Containerization solutions like Docker rely on features natively provided by Linux to achieve this. Running Docker on a non-Linux platform, like Windows or OS X requires hybrid approach running a Linux guest in a Virtual Machine – the Docker Toolbox and docker-machine takes care of this for you.

Next steps from this point would be to create your own image running some service or app in a container. If you look through some of my previous posts, hopefully these will now make more sense now we’ve covered some of the basics.

Go try it out for yourself!