Docker: A Quick Look

by John R. Ray (jray@shadow-soft.com)

So I’ve been using Docker for around 6 months now and I wanted to give people an idea of how easy it is to get started with. Today I’m going to show you how to get Docker running and build a simple nginx web server.

 

Before you begin

I’m going to be using Vagrant, for my virtual environment. This is not needed if you are running Docker locally. If you are using vagrant then please remember to forward port 80 traffic to a port on your host. This can be accomplished by adding the following to your Vagrantfile.

[[code]]czo1NDpcInMudm0ubmV0d29yayBcImZvcndhcmRlZF9wb3J0XCIsIGd1ZXN0OiA4MCwgaG9zdDogODA4MA0KXCI7e1smKiZdfQ==[[/code]]

Installing Docker

First thing, for me, is to bring up my vagrant environment. My Vagrantfile looks like

[[code]]czo3MjM6XCIkIGNhdCBWYWdyYW50ZmlsZQ0KIyAtKi0gbW9kZTogcnVieSAtKi0NCiMgdmk6IHNldCBmdD1ydWJ5IDoNCiNKb2huIFJ7WyYqJl19LiBSYXkNCiMgVmFncmFudGZpbGUgQVBJL3N5bnRheCB2ZXJzaW9uLiBEb25cJ3QgdG91Y2ggdW5sZXNzIHlvdSBrbm93IHdoYXQgeW97WyYqJl19dVwncmUgZG9pbmchDQpWQUdSQU5URklMRV9BUElfVkVSU0lPTiA9IFwiMlwiDQoNClZhZ3JhbnQuY29uZmlndXJlKFZBR1JBTlRGSUxFX3tbJiomXX1BUElfVkVSU0lPTikgZG8gfGNvbmZpZ3wNCiAgY29uZmlnLnZtLmJveCA9IFwiY2VudG9zLTY1LXg2NC1ub2NtXCINCiAgY29uZmlnLnZ7WyYqJl19bS5ib3hfdXJsID0gXCJodHRwOi8vcHVwcGV0LXZhZ3JhbnQtYm94ZXMucHVwcGV0bGFicy5jb20vY2VudG9zLTY1LXg2NC12aXJ0dWF7WyYqJl19bGJveC1ub2NtLmJveFwiDQoNCiAgIyMgU2VydmVyDQogIGNvbmZpZy52bS5kZWZpbmUgOnNlcnZlciBkbyB8c3wNCiAgICBzLnZtLnB7WyYqJl19cm92aWRlciA6dmlydHVhbGJveCBkbyB8dnwNCiAgICAgIHY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gdmFncmFudCBwcm97WyYqJl19dmlzaW9uYCBvciB1c2UgdGhlIGAtLXByb3Zpc2lvbmANCj09Jmd0OyBzZXJ2ZXI6IHRvIGZvcmNlIHByb3Zpc2lvbmluZy4gUHJvdntbJiomXX1pc2lvbmVycyBtYXJrZWQgdG8gcnVuIGFsd2F5cyB3aWxsIHN0aWxsIHJ1bi4NClwiO3tbJiomXX0=[[/code]]

Now I have a CentOS 6 VM. Graciously provided by the folks at Puppet Labs. So now I need to install Docker. (Output supressed for some commands) Docker for CentOS/RHEL 6 is provided in the epel repos. If you are using 7 then you can just.
[[code]]czoyMjpcIiMgeXVtIGluc3RhbGwgZG9ja2VyDQpcIjt7WyYqJl19[[/code]]

Otherwise…
[[code]]czozNjc6XCIkIHZhZ3JhbnQgc3NoIHNlcnZlcg0KDQpDb25zdWx0IHRoZSB1c2VyXCdzIGd1aWRlIGZvciBtb3JlIGRldGFpbHMgYWJve1smKiZdfXV0IFBPU0lYIHBhdGhzOg0KaHR0cDovL2N5Z3dpbi5jb20vY3lnd2luLXVnLW5ldC91c2luZy5odG1sI3VzaW5nLXBhdGhuYW1lcw17WyYqJl19Ckxhc3QgbG9naW46IFR1ZSBKYW4gIDYgMTE6MjA6NDMgMjAxNSBmcm9tIDEwLjAuMi4yDQpXZWxjb21lIHRvIHlvdXIgUGFja2VyLXtbJiomXX1idWlsdCB2aXJ0dWFsIG1hY2hpbmUuDQoNClt2YWdyYW50QHNlcnZlciB+XSQgc3VkbyBzdSAtDQpbcm9vdEBzZXJ2ZXIgfl0jIHl1e1smKiZdfW0gaW5zdGFsbCAteSBlcGVsLXJlbGVhc2UNCltyb290QHNlcnZlciB+XSMgeXVtIGluc3RhbGwgLXkgZG9ja2VyLWlvDQpcIjt7WyYqJl19[[/code]]

So now I should have docker installed and checking the version should give you something similar to the output below.
[[code]]czoyOTQ6XCJbcm9vdEBzZXJ2ZXIgfl0jIGRvY2tlciB2ZXJzaW9uDQpDbGllbnQgdmVyc2lvbjogMS4zLjINCkNsaWVudCBBUEkgdmV7WyYqJl19cnNpb246IDEuMTUNCkdvIHZlcnNpb24gKGNsaWVudCk6IGdvMS4zLjMNCkdpdCBjb21taXQgKGNsaWVudCk6IDM5ZmEyZmEvMS4zLntbJiomXX0yDQpPUy9BcmNoIChjbGllbnQpOiBsaW51eC9hbWQ2NA0KU2VydmVyIHZlcnNpb246IDEuMy4yDQpTZXJ2ZXIgQVBJIHZlcnNpb246e1smKiZdfSAxLjE1DQpHbyB2ZXJzaW9uIChzZXJ2ZXIpOiBnbzEuMy4zDQpHaXQgY29tbWl0IChzZXJ2ZXIpOiAzOWZhMmZhLzEuMy4yDQpcIjt7WyYqJl19[[/code]]

Docker Primer

I’m not going to do a command tutorial because the folks at docker have already provided a REALLY good one. Docker Tutorial. Go ahead and give it a try. I will wait.

Building a Dockerfile

Now that you are familiar with the docker commands let’s build a Dockerfile.

[[code]]czo4OTpcIltyb290QHNlcnZlciB+XSMgbWtkaXIgL25naW54ICZhbXA7JmFtcDsgY2QgL25naW54DQpbcm9vdEBzZXJ2ZXIgbmdpbnh7WyYqJl19XSMgdmltIERvY2tlcmZpbGUNClwiO3tbJiomXX0=[[/code]]

A Dockerfile contains all the commands you normally execute to build a Docker image.
[[code]]czoyMDpcIkZST00gZGViaWFuOmplc3NpZQ0KXCI7e1smKiZdfQ==[[/code]]

The FROM line tells Docker what image you want to start with. In this case I’m using Debian’s Jessie release. At this point I could execute a docker build and I would have the base debian:jessie image.

The next thing I want to do is install some packages. To execute commands we are going to use the RUN directive.

[[code]]czoxMjk6XCJGUk9NIGRlYmlhbjpqZXNzaWUNCg0KUlVOIGFwdC1nZXQgdXBkYXRlICZhbXA7JmFtcDsgYXB0LWdldCBpbnN0YWxsIC17WyYqJl19eQ0KICAgIGN1cmwNCiAgICBuZ2lueC1saWdodA0KICAgICZhbXA7JmFtcDsgYXB0LWdldCBjbGVhbg0KXCI7e1smKiZdfQ==[[/code]]

Now I have curl and nginx-light installed in my image. Now let’s hammer out the rest of this Dockerfile.
[[code]]czoyNDc6XCJGUk9NIGRlYmlhbjpqZXNzaWUNCg0KUlVOIGFwdC1nZXQgdXBkYXRlICZhbXA7JmFtcDsgYXB0LWdldCBpbnN0YWxsIC17WyYqJl19eQ0KICAgIGN1cmwNCiAgICBuZ2lueC1saWdodA0KICAgICZhbXA7JmFtcDsgYXB0LWdldCBjbGVhbg0KDQpSVU4gZWNobyBcImRhZW17WyYqJl19b24gb2ZmO1wiICZndDsmZ3Q7IC9ldGMvbmdpbngvbmdpbnguY29uZg0KDQpFWFBPU0UgODANCg0KQ01EIFtcIm5naW54XCIsIFwiLWNcIiwge1smKiZdfVwiL2V0Yy9uZ2lueC9uZ2lueC5jb25mXCJdDQpcIjt7WyYqJl19[[/code]]

So let’s look at what we have. First we are going to base this image of of debian jessie, we are then going to install curl and nginx light. Next we are going to tell nginx to run in the foreground so our container won’t crash, and we expose port 80 to the host. Finally we tell the image the default command that we want to execute when we launch a container.

Now we can build our image and run containers based on it.

[[code]]czo2NDc6XCJbcm9vdEBzZXJ2ZXIgbmdpbnhdIyBkb2NrZXIgYnVpbGQgLXQgeWFybmhvai9uZ2lueCAuDQpTZW5kaW5nIGJ1aWxkIGN7WyYqJl19b250ZXh0IHRvIERvY2tlciBkYWVtb24gNC42MDgga0INClNlbmRpbmcgYnVpbGQgY29udGV4dCB0byBEb2NrZXIgZGFlbW9uDQpTdHtbJiomXX1lcCAwIDogRlJPTSBkZWJpYW46amVzc2llDQogLS0tJmd0OyA4MzVjNGQyNzQwNjANClN0ZXAgMSA6IFJVTiBhcHQtZ2V0IHVwZGF0e1smKiZdfWUgJmFtcDsmYW1wOyBhcHQtZ2V0IGluc3RhbGwgLXkgICAgY3VybCAgICBuZ2lueC1saWdodCAgICAmYW1wOyZhbXA7IGFwdC1nZXR7WyYqJl19IGNsZWFuDQogLS0tJmd0OyBVc2luZyBjYWNoZQ0KIC0tLSZndDsgMjZkODIwMGY3MzNlDQpTdGVwIDIgOiBSVU4gZWNobyBcImRhZW17WyYqJl19b24gb2ZmO1wiICZndDsmZ3Q7IC9ldGMvbmdpbngvbmdpbnguY29uZg0KIC0tLSZndDsgVXNpbmcgY2FjaGUNCiAtLS0mZ3Q7IDFmNDF7WyYqJl19NmMyZWFmZTENClN0ZXAgMyA6IEVYUE9TRSA4MA0KIC0tLSZndDsgVXNpbmcgY2FjaGUNCiAtLS0mZ3Q7IGJjZGZkYWEyMmEwNA0KU3tbJiomXX10ZXAgNCA6IENNRCBuZ2lueCAtYyAvZXRjL25naW54L25naW54LmNvbmYNCiAtLS0mZ3Q7IFVzaW5nIGNhY2hlDQogLS0tJmd0OyAze1smKiZdfWYyNTdiYTczN2IzDQpTdWNjZXNzZnVsbHkgYnVpbHQgM2YyNTdiYTczN2IzDQpcIjt7WyYqJl19[[/code]]

Now if you are building this for the first time you are going to see A LOT more information. I’ve built this image before so what I see is cached layers getting reused.

Now take a look at your images.

[[code]]czozMDg6XCJbcm9vdEBzZXJ2ZXIgbmdpbnhdIyBkb2NrZXIgaW1hZ2VzDQpSRVBPU0lUT1JZICAgICAgICAgIFRBRyAgICAgICAgICB7WyYqJl19ICAgICAgIElNQUdFIElEICAgICAgICAgICAgQ1JFQVRFRCAgICAgICAgICAgICBWSVJUVUFMIFNJWkUNCnlhcm5ob2ovbmdpbnggIHtbJiomXX0gICAgIGxhdGVzdCAgICAgICAgICAgICAgM2YyNTdiYTczN2IzICAgICAgICAyIGRheXMgYWdvICAgICAgICAgIDE1MCBNQg0KZGVie1smKiZdfWlhbiAgICAgICAgICAgICAgamVzc2llICAgICAgICAgICAgICA4MzVjNGQyNzQwNjAgICAgICAgIDggZGF5cyBhZ28gICAgICAgICB7WyYqJl19IDEyMi42IE1CDQpcIjt7WyYqJl19[[/code]]

Running a Container

The docker run command takes several options. Let’s look at the complete command and talk about what it’s doing.

[[code]]czo0NDM6XCJbcm9vdEBzZXJ2ZXIgbmdpbnhdIyBkb2NrZXIgcnVuIC1pdCAtZCAtLW5hbWUgd2ViIC1wIDgwOjgwIHlhcm5ob2ovbmd7WyYqJl19aW54DQo5NzE0OTA5NzU4ZjY1MDQxN2M2ZDdlMjRmZjJmZWE5ZTEzNTVhZGM0M2ViMWMxNzg3ODIxNzFhOGZlNjRiZGIxDQpbcm9vdHtbJiomXX1Ac2VydmVyIG5naW54XSMgZG9ja2VyIHBzDQpDT05UQUlORVIgSUQgICAgICAgIElNQUdFICAgICAgICAgICAgICAgICAgQ09NTUFOe1smKiZdfUQgICAgICAgICAgICAgICAgQ1JFQVRFRCAgICAgICAgICAgICBTVEFUVVMgICAgICAgICAgICAgIFBPUlRTICAgICAgICAgICAgICB7WyYqJl19ICAgIE5BTUVTDQo5NzE0OTA5NzU4ZjYgICAgICAgIHlhbnJob2ovbmdpbng6bGF0ZXN0ICAgXCJuZ2lueCAtYyAvZXRjL25naW54ICB7WyYqJl19IDIgc2Vjb25kcyBhZ28gICAgICAgVXAgMSBzZWNvbmRzICAgICAgICAwLjAuMC4wOjgwLSZndDs4MC90Y3AgICB3ZWINClwiO3tbJiomXX0=[[/code]]

This command tells docker to do the following:

  • -it -d – Run an keep STDIN open, Allocate a TTY, and run in detached mode.
  • -name web – Name my container web.
  • -p 8080:80 – Map port 80 on the host to port 80 in the container.
  • yarnhoj/nginx – The image name to start from.

You can now run docker ps and see that your container is running.

But is it really?

[[code]]czoxMTEwOlwiW3Jvb3RAc2VydmVyIG5naW54XSMgY3VybCBsb2NhbGhvc3QNCiZsdDshRE9DVFlQRSBodG1sJmd0Ow0KJmx0O2h0bWx7WyYqJl19Jmd0Ow0KJmx0O2hlYWQmZ3Q7DQombHQ7dGl0bGUmZ3Q7V2VsY29tZSB0byBuZ2lueCBvbiBEZWJpYW4hJmx0Oy90aXRsZSZndDsNCntbJiomXX0mbHQ7c3R5bGUmZ3Q7DQogICAgYm9keSB7DQogICAgICAgIHdpZHRoOiAzNWVtOw0KICAgICAgICBtYXJnaW46IDAgYXV0bzsNCiAge1smKiZdfSAgICAgIGZvbnQtZmFtaWx5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JlZm9yZSByZXBvcnRpbmcgYSBuZXcgYnVne1smKiZdfS4NCiZsdDsvcCZndDsNCg0KJmx0O3AmZ3Q7Jmx0O2VtJmd0O1RoYW5rIHlvdSBmb3IgdXNpbmcgZGViaWFuIGFuZCBuZ2lueC4mbHR7WyYqJl19Oy9lbSZndDsmbHQ7L3AmZ3Q7DQoNCg0KJmx0Oy9ib2R5Jmd0Ow0KJmx0Oy9odG1sJmd0Ow0KXCI7e1smKiZdfQ==[[/code]]

You now have a functioning web server running in a container. Go open a web browser and hit localhost:8080. (That’s what I have vagrant set up to forward traffic to.)

So the default index.html is kinda lame so as a parting shot let’s modify it with a standard hello world.

Customizing nginx

A couple of tasks to complete.

  • Create the index.html in the same directory as our Dockerfile
  • Tell Docker to add that file to our image

Adding your own index.html

[[code]]czo2MTpcIltyb290QHNlcnZlciBuZ2lueF0jIGVjaG8gXCJIZWxsbyBXb3JsZFwiICZndDsmZ3Q7IGluZGV4Lmh0bWwNClwiO3tbJiomXX0=[[/code]]

Modify the Dockerfile

[[code]]czozNDM6XCJbcm9vdEBzZXJ2ZXIgbmdpbnhdIyB2aW0gRG9ja2VyZmlsZQ0KRlJPTSBkZWJpYW46amVzc2llDQoNClJVTiBhcHQtZ2V7WyYqJl19dCB1cGRhdGUgJmFtcDsmYW1wOyBhcHQtZ2V0IGluc3RhbGwgLXkNCiAgICBjdXJsDQogICAgbmdpbngtbGlnaHQNCiAgICAmYW1wO3tbJiomXX0mYW1wOyBhcHQtZ2V0IGNsZWFuDQoNClJVTiBlY2hvIFwiZGFlbW9uIG9mZjtcIiAmZ3Q7Jmd0OyAvZXRjL25naW54L25naW54LmNvbmZ7WyYqJl19DQoNCkNPUFkgaW5kZXguaHRtbCAvdmFyL3d3dy9odG1sLyAjJmx0Oy0tLS0tLUFERCBUSElTIExJTkUNCg0KRVhQT1NFIDgwDQoNCntbJiomXX1DTUQgW1wibmdpbnhcIiwgXCItY1wiLCBcIi9ldGMvbmdpbngvbmdpbnguY29uZlwiXQ0KXCI7e1smKiZdfQ==[[/code]]

The copy command is going to do exactly what you think it will.

Rebuild

[[code]]czo4NzM6XCJbcm9vdEBzZXJ2ZXIgbmdpbnhdIyBkb2NrZXIgYnVpbGQgLXQgeWFybmhvai9uZ2lueCAuDQpTZW5kaW5nIGJ1aWxkIGN7WyYqJl19b250ZXh0IHRvIERvY2tlciBkYWVtb24gNC42MDgga0INClNlbmRpbmcgYnVpbGQgY29udGV4dCB0byBEb2NrZXIgZGFlbW9uDQpTdHtbJiomXX1lcCAwIDogRlJPTSBkZWJpYW46amVzc2llDQogLS0tJmd0OyA4MzVjNGQyNzQwNjANClN0ZXAgMSA6IFJVTiBhcHQtZ2V0IHVwZGF0e1smKiZdfWUgJmFtcDsmYW1wOyBhcHQtZ2V0IGluc3RhbGwgLXkgICAgY3VybCAgICBuZ2lueC1saWdodCAgICAmYW1wOyZhbXA7IGFwdC1nZXR7WyYqJl19IGNsZWFuDQogLS0tJmd0OyBVc2luZyBjYWNoZQ0KIC0tLSZndDsgMjZkODIwMGY3MzNlDQpTdGVwIDIgOiBSVU4gZWNobyBcImRhZW17WyYqJl19b24gb2ZmO1wiICZndDsmZ3Q7IC9ldGMvbmdpbngvbmdpbnguY29uZg0KIC0tLSZndDsgVXNpbmcgY2FjaGUNCiAtLS0mZ3Q7IDFmNDF7WyYqJl19NmMyZWFmZTENClN0ZXAgMyA6IENPUFkgaW5kZXguaHRtbCAvdmFyL3d3dy9odG1sLw0KIC0tLSZndDsgNDRkMDE1YTA5NDdmDQpSZXtbJiomXX1tb3ZpbmcgaW50ZXJtZWRpYXRlIGNvbnRhaW5lciAxZjgxNjFlNmIyZjMNClN0ZXAgNCA6IEVYUE9TRSA4MA0KIC0tLSZndDsgUnVue1smKiZdfW5pbmcgaW4gZTkyYTc1Yzc3NDJkDQogLS0tJmd0OyA4YzZhODRkY2I0MTUNClJlbW92aW5nIGludGVybWVkaWF0ZSBjb250YWluZXJ7WyYqJl19IGU5MmE3NWM3NzQyZA0KU3RlcCA1IDogQ01EIG5naW54IC1jIC9ldGMvbmdpbngvbmdpbnguY29uZg0KIC0tLSZndDsgUnVubmluZ3tbJiomXX0gaW4gZTYzYjNlZWFlMDBhDQogLS0tJmd0OyA1MGFkNGFjYTVhOTUNClJlbW92aW5nIGludGVybWVkaWF0ZSBjb250YWluZXIgZTYze1smKiZdfWIzZWVhZTAwYQ0KU3VjY2Vzc2Z1bGx5IGJ1aWx0IDUwYWQ0YWNhNWE5NQ0KXCI7e1smKiZdfQ==[[/code]]

You will probabaly notice that this build took a fraction longer than you would have thought. That is because when you add/modify a line to a Dockerfile it invalidates the cache below it. What this means is you want to put heavy operations, like package installs, at the top of your Dockerfile.

Let’s stop our running nginx container and then launch the new one.

[[code]]czo3MzpcIltyb290QHNlcnZlciBuZ2lueF0jIGRvY2tlciBzdG9wIHdlYiAmYW1wOyZhbXA7IGRvY2tlciBybSB3ZWINCndlYg0Kd2V7WyYqJl19Yg0KXCI7e1smKiZdfQ==[[/code]]

Now launch a new container.
[[code]]czo0OTQ6XCJbcm9vdEBzZXJ2ZXIgbmdpbnhdIyBkb2NrZXIgcnVuIC1pdCAtZCAtLW5hbWUgd2ViIC1wIDgwOjgwIHlhcm5ob2ovbmd7WyYqJl19aW54DQo0YzA5NGI2NGQwMzU1ZWQzOTYyZjJlNGExNThjZGE1YzJkNmEzZTYzODkwYTUxZjBjNjBlYTk4ZmJlMTk2OWMxDQpbcm9vdHtbJiomXX1Ac2VydmVyIG5naW54XSMgZG9ja2VyIHBzDQpDT05UQUlORVIgSUQgICAgICAgIElNQUdFICAgICAgICAgICAgICAgICAgQ09NTUFOe1smKiZdfUQgICAgICAgICAgICAgICAgQ1JFQVRFRCAgICAgICAgICAgICBTVEFUVVMgICAgICAgICAgICAgIFBPUlRTICAgICAgICAgICAgICB7WyYqJl19ICBOQU1FUw0KNGMwOTRiNjRkMDM1ICAgICAgICB5YW5yaG9qL25naW54OmxhdGVzdCAgIFwibmdpbnggLWMgL2V0Yy9uZ2lueCAgIDN7WyYqJl19IHNlY29uZHMgYWdvICAgICAgIFVwIDIgc2Vjb25kcyAgICAgICAgMC4wLjAuMDo4MC0mZ3Q7ODAvdGNwICAgd2ViIA0KDQpbcm9vdHtbJiomXX1Ac2VydmVyIG5naW54XSMgY3VybCBsb2NhbGhvc3QNCkhlbGxvIFdvcmxkDQpcIjt7WyYqJl19[[/code]]

Happy Hacking!

JR|Ray

Interested in learning more how Docker can revolutionize your Development lifecycle? As an authorized Docker partner and integrator, Shadow-Soft has the expertise to explore Docker use cases in your specific environments.  Fill out this form and we’ll be in touch within 24 hours.