Running a local insecure Docker Registry for testing

To start and run a local Repository for sharing images between machines (from here):

docker run -d -p 5000:5000 --restart=always --name registry registry:2

To tag a local image and push it into your repository:

docker tag imagename [ip of your docker machine]:5000/imagename

And then push it into your repo:

docker push [ip of your docker machine]:5000/imagename

By default, the docker client fails when attempting to push an image to a locally running registry if you haven’t configured TLS and certificates. If you’re running a registry locally for testing, you can configure the local client to trust an insecure Registry by:

  • docker-machine ssh [name of docker machine]
  • sudo vi /var/lib/boot2docker/profile
  • Add this line to the EXTRA_ARGS var:
--insecure-registry=[ip of your docker machine]:5000

This tip from this article.

Update1: if running on Linux (no docker-machine), add the above property to /etc/default/docker and then

sudo service docker restart

Update2: if docker is running as a service using systemd (e.g. the Hypriot Raspberry Pi image), you need to edit

/etc/systemd/system/docker.service

… append the –insecure-registry option to the end of the line that starts: ExecStart (further details here)

Now trying the push again, and success!

$ docker push 192.168.99.100:5000/spring-boot-rest-alpine

The push refers to a repository [192.168.99.100:5000/spring-boot-rest-alpine]

d5a685774b12: Pushed 

726baddb2cde: Pushed 

bb81ee534db3: Pushed 

77f08abee8bf: Pushed 

latest: digest: sha256:cafa45a64cf25533a1544f37ef7ee3fac614cb2a8d8be30efe9b3c84cebabc52 size: 1159

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 🙂

Lightweight docker images for Java apps

There’s a number of posts (e.g. here) talking about the official Java docker images being on the large side – in Docker terms, the standard images at > 600MB before you even build your image containing you app are … pretty big.

Suggestions are to use a smaller image as a starting point, like Alpine Linux. It looks like at some point the official Java images have been updates to include a number of Alpine based images too.

Pulling down an OpenJDK 8 image, java:openjdk-8-jdk and then java:openjdk-8-alpine, there’s a massive size difference between the size of the two:

If you’re planning on running something lightweight like a Spring Boot app, looks like the provided Alpine images are a good starting point.

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