* Warning this post contains mildly anti-Windows sentiments *
It has never been easier to get ‘hands-on’ with Infrastructure Coding and Containers (yes including Docker), even if your daily life is spent using a Windows work laptop. My friend Kumar and I proved this the other Saturday night in just one hour in a bar in Chennai. Here are the steps we performed on his laptop. I encourage you to do the same (with an optional side order of Kingfisher Ultra).
- We installed Docker Toolbox.
It turns out this is an extremely fruitful first step as it gives you:
- Git (and in particular GitBash). This allows you to use the world’s best Software Configuration Management tool Git and welcomes you into the world of being able to use and contribute to Open Source software on Git Hub. Plus it has the added bonus of turning your laptop into something which understands good wholesome Linux commands.
- Virtual Box. This is a hypervisor that turns your laptop from being one machine running one Operating System (Windoze) into something capable of running multiple virtual machines with almost any Operating System you want (even UniKernels!). Suddenly you can run (and develop) local copies of servers that from a software perspective match Production.
- Docker Machine. This is a command line utility that will create virtual machines for running Docker on. It can do this either locally on your shiny new Virtual Box instance or remotely in the cloud (even the Azure cloud – Linux machines of course)
- Docker command line. This is the main command line utility of Docker. This will enable you to download and build Docker images, and turn them into running Docker containers. The beauty of the Docker command line is that you can run it locally (ideally in GitBash) on your local machine and have it control Docker running on a Linux machine. See diagram below.
- Docker Compose. This is a utility that gives you the ability to run and associate multiple Docker containers by reading what is required from a text file.
- Having completed step 1, we opened up the Docker Quickstart Terminal by clicking the entry that had appeared in the Windows start menu. This runs a shell script via GitBash that performs the following:
- Creates a virtual box machine (called ‘default’) and starts it
- Installs Docker on the new virtual machine
- Leaves you with a GitBash window open that has the necessary environment variables set to instruct point Docker command line utility to point at your new virtual machine.
- We wanted to test things out, so we ran:
$ docker ps –a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
This showed us that our Docker command line tool was successfully talking to the Docker daemon (process) running on the ‘default’ virtual machine. And it showed us that no containers were either running or stopped on there.
- We wanted to testing things a little further so ran:
$ docker run hello-world Hello from Docker. This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: The Docker client contacted the Docker daemon. The Docker daemon pulled the "hello-world" image from the Docker Hub. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker Hub account: https://hub.docker.com For more examples and ideas, visit: https://docs.docker.com/userguide
The output is very self-explanatory. So I recommend reading it now.
- We followed the instructions above to run a container from the Ubuntu image. This started for us a container running Ubuntu and we ran a command to satisfy ourselves that we were running Ubuntu. Note one slight modification, we had to prefix the command with ‘winpty’ to work around a tty-related issue in GitBash
$ winpty docker run -it ubuntu bash root@2af72758e8a9:/# apt-get -v | head -1 apt 1.0.1ubuntu2 for amd64 compiled on Aug 1 2015 19:20:48 root@2af72758e8a9:/# exit $ exit
- We wanted to run something else, so we ran:
$ docker run -d -P nginx:latest
- This caused the Docker command line to do more or less what is stated in the previous step with a few exceptions.
- The –d flag caused the container to run in the background (we didn’t need –it).
- The –P flag caused docker to expose the ports of Nginx back to our Windows machine.
- The Image was Nginx rather than Ubuntu. We didn’t need to specify a command for the container to run after starting (leaving it to run its default command).
- We then ran the following to establish how to connect to our Nginx:
$ docker-machine ip default 192.168.99.100 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 826827727fbf nginx:latest "nginx -g 'daemon off" 14 minutes ago Up 14 minutes 0.0.0.0:32769->80/tcp, 0.0.0.0:32768->443/tcp ecstatic_einstein
- We opened a proper web brower (Chrome) and navigated to: http://192.168.99.100:32769/ using the information above (your IP address may differ). Pleasingly we were presented with the: ‘Welcome to nginx!’ default page.
- We decided to clean up some of what we’re created locally on the virtual machine, so we ran the following to:
- Stop the Nginx container
- Delete the stopped containers
- Demonstrate that we still had the Docker ‘images’ downloaded
$ docker kill `docker ps -q` 8d003ca14410 $ docker rm `docker ps -aq` 8d003ca14410 2af72758e8a9 … $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE nginx latest sha256:99e9a 4 weeks ago 134.5 MB ubuntu latest sha256:3876b 5 weeks ago 187.9 MB hello-world latest sha256:690ed 4 months ago 960 B
- We went back to Chrome and hit refresh. As expected Nginx was gone.
- We opened Oracle VM Virtual box from the Windows start machine so that we could observe our ‘default’ machine listed as running.
- We ran the following to stop our ‘default’ machine and also observed it then stopping Virtual Box:
$ docker-machine stop default
- Finally we installed Vagrant. This is essentially a much more generic version of Docker-Machine that is capable of creating not just virtual machines in Virtual Box for Docker, but for many other purposes. For example from an Infrastructure Coding perspective, you might run a virtual machine for developing Chef code.
Not bad for one hour on hotel wifi!
Kumar keenly agreed he would complete the following next steps. I hope you’ll join him on the journey and Start Infrastructure Coding Today!
- Learn Git. It really only takes 10 minutes with this tutorial LINK to learn the basics.
- Docker – continue the journey here
Please share any issues following this and I’ll improve the instructions. Please share any other useful tutorials and I will add those also.