<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by John Ray on Medium]]></title>
        <description><![CDATA[Stories by John Ray on Medium]]></description>
        <link>https://medium.com/@theYarNhoj?source=rss-2b7e6984d990------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*wxZ4jKS7OQilipHO.jpg</url>
            <title>Stories by John Ray on Medium</title>
            <link>https://medium.com/@theYarNhoj?source=rss-2b7e6984d990------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 14:05:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@theYarNhoj/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Nginx Reverse Proxy for your Docker Registry]]></title>
            <link>https://medium.com/@theYarNhoj/nginx-reverse-proxy-for-your-docker-registry-cb90e7b967ca?source=rss-2b7e6984d990------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb90e7b967ca</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[John Ray]]></dc:creator>
            <pubDate>Tue, 02 Feb 2016 20:56:36 GMT</pubDate>
            <atom:updated>2016-02-02T20:56:36.574Z</atom:updated>
            <content:encoded><![CDATA[<p>Who is tired of typing :5000 every time you push or pull something from your private registry? Since everyone is raising their hands and several of you are screaming in fits of rage, I’m going to tell you a really quick way to set up Nginx to reverse proxy our traffic from port 80 and 443 to 5000.</p><h3>Nginx?</h3><p>Nginx (pronounced “engine x”) is a web server with a strong focus on high concurrency, performance and low memory usage. It can also act as a reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer and an HTTP cache. It also has an official image maintained in the Docker hub and all the cool kids are doing it.</p><p>Log in to your registry server and pull down the official nginx image.</p><pre>a578992@vc2coma2067822n:~$ docker pull nginx Using default tag: latest latest: Pulling from library/nginx 7a42f1433a16: Pull complete 3d88cbf54477: Pull complete fbdef4a4ff6b: Pull complete 067439a15e7d: Pull complete 24c1dc27266b: Pull complete 1acf3046c96d: Pull complete 3298e91823c1: Pull complete 15340d6ed415: Pull complete 06908a7ce444: Pull complete fc68e18b17d8: Pull complete 0b9b1560f5e9: Pull complete 52d0c47f4ca7: Pull complete Digest: sha256:44e64351e39e67b07799a1ce448cef33aaa88daedbbb5f427fac4eeafe3e148f Status: Downloaded newer image for nginx:latest a578992@vc2coma2067822n:~$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE nginx latest 52d0c47f4ca7 13 days ago 132.9 MB registry 2 2eafecf5086b 2 weeks ago 220.7 MB</pre><p>According to the <a href="https://hub.docker.com/_/nginx/">Nginx README</a> we sould just be able to:</p><pre>$ docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx</pre><p>That doesn’t really help us all that much since the default nginx config is kind of bland. Here is my site config.</p><pre>a578992@vc2coma1066091n:/docker/nginx &gt; cat reg.johnray.io.conf # Define Upstream upstream registry { server reg:5000; } # http redirects to https server { listen 80; server_name reg.johnray.io; # Strict Transport Security add_header Strict-Transport-Security max-age=2592000; rewrite ^/.*$ <a href="https://$host$request_uri/?">https://$host$request_uri?</a> permanent; } server { listen 443; server_name reg.johnray.io; client_max_body_size 0; # Disabled to prevent 413&#39;s ssl_certificate /etc/nginx/certs/docker-registry-v2.crt; ssl_certificate_key /etc/nginx/certs/docker-registry-v2.key; ssl on; ssl_session_cache builtin:1000 shared:SSL:10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4; ssl_prefer_server_ciphers on; access_log /var/log/nginx/registry.access.log; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; # Fix the “It appears that your reverse proxy set up is broken&quot; error. proxy_pass <a href="https://registry;/">https://registry;</a> proxy_read_timeout 90; } }</pre><p>This is pretty barebones and essentially redirects port 80 to 443 and then on to 5000. In the upstream section you will see that I call my server reg:5000. We will talk about how that works when we launch the container. To make things easy you can copy paste this config. Everywhere you see reg.johnray.io you should insert your registry name. reg.johnray.io doesn’t exists and even if it did it wouldn’t help you to try and reverse proxy sommone else’s registry.</p><p>Save your config somewhere, mine is in /docker/nginx/reg.johnray.io.conf, and let’s get to launching the container.</p><h3>3..2..1..Launch</h3><p>If you followed my previous post you will already have some ssl certs so let’s use those. They should be somwhere like /docker/certs.</p><p>Launch your container like so.</p><pre>$ docker run -d --restart=always --name nginx -v /docker/nginx/reg.johnray.io.conf:/etc/nginx/conf.d/default.conf -v /docker/certs:/etc/nginx/certs -p 80:80 -p 443:443 --link registry:reg nginx</pre><p>So we are launching a container with a restart polocy of always, just in case it crashes, a name of nginx, some volume mounts for our default config (I’m just overwritting the default here instead of trying to have multiple sites) and our SSL certificates, we are mapping some ports, and finally we are likning our registry container. That’s the magic that makes the reg:5000 entry work in the reg.johnray.io.conf file.</p><p>Once this is up and running test it by tagging one of your localhost images.</p><pre>docker tag reg.johnray.io:5000/docker-chrome reg.johnray.io/docker-chrome docker push reg.johnray.io/docker-chrome</pre><p>If all goes well your image should now happily push to your registry server. Better yet any Docker host that trusts your self signed cert, or your real cert if you have one, will be able to push to your registry without :5000.</p><p>Happy Hacking!</p><p><a href="http://blog.johnray.io/">John R. Ray</a></p><p><em>Originally published at </em><a href="http://blog.johnray.io/nginx-reverse-proxy-for-your-docker-registry"><em>blog.johnray.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb90e7b967ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up a Docker V2 Registry]]></title>
            <link>https://medium.com/@theYarNhoj/setting-up-a-docker-v2-registry-8a3eb3770e2f?source=rss-2b7e6984d990------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a3eb3770e2f</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[John Ray]]></dc:creator>
            <pubDate>Tue, 02 Feb 2016 20:55:42 GMT</pubDate>
            <atom:updated>2016-02-02T20:55:42.715Z</atom:updated>
            <content:encoded><![CDATA[<p>So the v2 implementation of the Docker Registry is out. You can find it <a href="https://github.com/docker/distribution">here</a>. As I continue to experiment with containerization I though it would be nice to have a private registry for me to work out of.</p><p>In order for this to work you need to be running docker ~&gt; 1.6. I’m using 1.8.3 in this example. You will also need an image to push so if you don’t have one feel free to clone my <a href="https://github.com/YarNhoj/docker-chrome.git">chrome running in docker</a> image.</p><p>Follow the instructions for how to build it…it’s in the README.</p><p>If you didn’t read that in the voice of the Knights Who Say Ni then go back and do that now. It’s OK, I’ll wait while you look them up…actually <a href="http://lmgtfy.com/?q=The+Knights+Who+Say+Ni">Let me google that for you</a>. Can we move on now? Good. While you can build the registry from scratch it’s actually easier to just pull it from the official Docker Repo, and for the purposes of this document that’s what we are going to do. Fire up a ssh session to your favorite instance and:</p><p>The tag part is important because if you just pull the registry you are going to get v1 and who wants v1 of anything? We are containerizing people! Living on the bleeding edge!<br> Once you have the registry down we can quick launch it like so.</p><pre>docker run -d -p 5000:5000 --restart=always --name registry registry:2</pre><p>This starts our registry container, maps port 5000 on the host to 5000 in the container gives it a name of registry and also introduces us to the <a href="https://docs.docker.com/reference/run/#restart-policies-restart">restart policies</a>.</p><p>Container restart policies do exactly what you think they should. If your container crashes for any reason the Docker daemon will try to bring it back up. The default is no, but you can also specify max retries and always.<br> With our registry running let’s tag an image to our local repo and push it.</p><pre>docker tag docker-chrome localhost:5000/docker-chrome</pre><p>Before you start complaining about the longish format of private container names remember that the root namespace, ie busybox, is really index.docker.io/library/busybox. Docker shortens that down for you so that you don’t have to type it all out, but you need to get used to working with fully qualified image names or FQIN. FQIN’s allow you to specify any private registry to push and pull from so whereas typing docker pull busybox is going to get expanded to docker pull index.docker.io/library/busybox typing docker pull localhost:5000/busybox is going to get you the version that would be hosted internally if in fact you hosted library images internally, which you don’t.</p><p>With our chrome image tagged go ahead and push it to the registry.</p><pre>a578992@vc2coma1066091n:~/docker-chrome &gt; docker push localhost:5000/docker-chrome The push refers to a repository [localhost:5000] (len: 1) 0e16757e7b5d: Image already exists 9fb555344e55: Image already exists 223b636e1f84: Image already exists 0567a7a943c5: Image already exists 4a275333f760: Image already exists 50a59a17c41c: Image already exists 319c8b61759b: Image already exists a8a49eee0527: Image already exists abf780c5faaa: Image already exists d64fc71e054c: Image already exists 302e187e53f6: Image already exists f359075ce4d8: Image already exists latest: digest: sha256:6390e332b841087a5ff94d25a82a0a675dc7ee92d5509893e245bd61efee897c size: 20487</pre><p>Your push is going to look slightly different since you wont already have the image in your registry. Now delete the image from your system with</p><pre>a578992@vc2coma1066091n:~/project/docker-chrome &gt; docker rmi localhsot:5000/docker-chrome Untagged: localhost:5000/docker-chrome:latest Deleted: 0e16757e7b5d01acf50a26d11f59d1d3a1708791b699f9c9f8da54ca2b97aae8 Deleted: 9fb555344e556e3d12666f5484d01232bfcf36a2e12f7012b999d0d079b8e204 Deleted: 223b636e1f84a814b04cd9b6650d9a43328eb1dd082215f6b4facc8fcced6fe2 Deleted: 0567a7a943c5648ed36bfd57ab85e333bedd14831932678f9240693f34e244e7 Deleted: 4a275333f7604b85cc53c6e79fbba29743fbaf9edc805c8f3313619116144516 Deleted: 50a59a17c41c06ea40e9b779daf7b6b465a7b58e7508ed1f01872f515b771bd3 Deleted: 319c8b61759bc291da78141819a2d3037ec0a2ea428dc262980c4d442dd63204 Deleted: a8a49eee05276133cfafefa4d49e8e014ecc12a9014d3d4e3762bd0889fa186b Deleted: abf780c5faaa62826830f88c93ffcf494ae61c1d2d273e59350195443b3f77f1</pre><p>and download it again with</p><pre>a578992@vc2coma1066091n:~/project/docker-chrome &gt; docker pull localhost:5000/docker-chrome Using default tag: latest latest: Pulling from docker-chrome cea0f0c83002: Pull complete e0c92a5263ea: Pull complete 5d1c42bc22e0: Pull complete 29bb38f6024f: Pull complete 5f7e11028271: Pull complete 57139ca9a9b7: Pull complete 617feda6b6d2: Pull complete 62ce07b6ddc0: Pull complete aceddd13fdf9: Pull complete f359075ce4d8: Already exists 302e187e53f6: Already exists d64fc71e054c: Already exists Digest: sha256:6390e332b841087a5ff94d25a82a0a675dc7ee92d5509893e245bd61efee897c Status: Downloaded newer image for localhost:5000/docker-chrome:latest</pre><p>To stop your registry you would docker stop registry &amp;&amp; docker rm -v registry</p><p>One big thing to pay attention to is the storage backend for registries. By default data is stored in a docker volume which is NOT persistent, meaning that if you rm -v your registry your content is gone. Docker has a bunch of <a href="https://github.com/docker/distribution/blob/master/docs/storagedrivers.md">storage drivers</a>. The easiest thing to do is mount a data volume so you get something like this</p><pre>docker run -d -p 5000:5000 -v /docker/registry:/var/lib/registry --restart=always --name registry registry:2</pre><p>Having your own local registry is fun, but what if you want to run your own domain registry? The v2 registry lets you do this but also enforces the use of TLS, which means you are going to have to generate some SSL certs. You still need to get a real SSL cert for your registry though so go ahead and get one from somwhere like <a href="https://www.startssl.com/">startssl</a>. Until you do that make your life a little easier by pulling the openssl container from <a href="https://labs.ctl.io/">centurylink labs</a>.</p><pre>docker pull centurylink/openssl</pre><p>This nifty little container already has the openssl bits you need to make your very own self signed certs. Run it like so</p><pre>docker run --rm -e COMMON_NAME=&lt;Common Name&gt; -e KEY_NAME=&lt;Cert File Names Prefix&gt; -v /docker/certs:/certs centurylink/openssl</pre><p>Where the common_name is the fqdn of your registry, reg.fmr.com in my case, and the Key_Name is just a prefix.</p><p>Now you should have a .key, .crt, and .csr in /docker/certs. Let’s blow away our old insecure registry and replace it with a brand new one.</p><pre>docker stop registry &amp;&amp; docker rm -v registry docker run -d -p 5000:5000 --restart=always --name registry -v /docker/certs:/certs -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/&lt;prefix&gt;.crt -e REGISTRY_HTTP_TLS_KEY=/certs/&lt;prefix&gt;.key registry:2</pre><p>Using a self signed cert does have one itty bitty problem. You have to tell docker to explicity trust the cert.</p><pre>sudo mkdir /etc/docker/certs.d/&lt;fqdn&gt;:5000 &amp;&amp; sudo cp /docker/certs/&lt;prefix&gt;.crt /etc/docker/certs.d/&lt;fqdn&gt;:5000/ca.crt sudo service docker restart</pre><p>Remember when I told you to get a real SSL certs several paragraphs ago? This is why. You need to do this on EVERY docker host that will connect to your registry. Although once you do you will be able to push from other hosts to your fqdn:port.</p><p>Happy Hacking!</p><p><em>Originally published at </em><a href="http://blog.johnray.io/setting-up-a-docker-v2-registry"><em>blog.johnray.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a3eb3770e2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started w/ Docker]]></title>
            <link>https://medium.com/@theYarNhoj/getting-started-w-docker-ec2aaa40577b?source=rss-2b7e6984d990------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec2aaa40577b</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[John Ray]]></dc:creator>
            <pubDate>Tue, 02 Feb 2016 20:54:13 GMT</pubDate>
            <atom:updated>2016-02-02T20:54:13.019Z</atom:updated>
            <content:encoded><![CDATA[<p>This post was originally published Jan 9th 2015.</p><p>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.</p><h3>Before you begin</h3><p>I’m going to be using <a href="https://www.vagrantup.com/">Vagrant</a>, 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.</p><p>s.vm.network “forwarded_port”, guest: 80, host: 8080</p><h3>Installing Docker</h3><p>First thing, for me, is to bring up my vagrant environment. My Vagrantfile looks like</p><pre># # -*- mode: ruby -*- # vi: set ft=ruby : #John R. Ray # Vagrantfile API/syntax version. Don&#39;t touch unless you know what you&#39;re doing! VAGRANTFILE_API_VERSION = &quot;2&quot; Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = &quot;centos-65-x64-nocm&quot; config.vm.box_url = &quot;http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box&quot; ## Server config.vm.define :server do |s| s.vm.provider :virtualbox do |v| v.memory = 1024 v.cpus = 2 end s.vm.network :private_network, ip: &quot;10.10.100.100&quot; s.vm.network &quot;forwarded_port&quot;, guest: 80, host: 8080 s.vm.hostname = &#39;server.johnray.io&#39; s.vm.provision :hosts end end</pre><p>And now I’ll bring up my VM.</p><pre>$ vagrant up server Bringing machine &#39;server&#39; up with &#39;virtualbox&#39; provider... ==&gt; server: Clearing any previously set forwarded ports... ==&gt; server: Clearing any previously set network interfaces... ==&gt; server: Preparing network interfaces based on configuration... server: Adapter 1: nat server: Adapter 2: hostonly ==&gt; server: Forwarding ports... server: 80 =&gt; 8080 (adapter 1) server: 22 =&gt; 2222 (adapter 1) ==&gt; server: Running &#39;pre-boot&#39; VM customizations... ==&gt; server: Booting VM... ==&gt; server: Waiting for machine to boot. This may take a few minutes... server: SSH address: 127.0.0.1:2222 server: SSH username: vagrant server: SSH auth method: private key server: Warning: Connection timeout. Retrying... server: Warning: Remote connection disconnect. Retrying... ==&gt; server: Machine booted and ready! ==&gt; server: Checking for guest additions in VM... ==&gt; server: Setting hostname... ==&gt; server: Configuring and enabling network interfaces... ==&gt; server: Mounting shared folders... server: /vagrant =&gt; C:/Users/John/project/nginx ==&gt; server: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==&gt; server: to force provisioning. Provisioners marked to run always will still run.</pre><p>Now I have a CentOS 6 VM. Graciously provided by the folks at <a href="http://puppetlabs.com/">Puppet Labs</a>. So now I need to install Docker. (Output suppressed for some commands) Docker for CentOS/RHEL 6 is provided in the epel repos. If you are using 7 then you can just.</p><pre>$ sudo yum install -y docker</pre><p>Otherwise…</p><pre>$ vagrant ssh server Consult the user&#39;s guide for more details about POSIX paths: <a href="http://cygwin.com/cygwin-ug-net/using.html#using-pathnames">http://cygwin.com/cygwin-ug-net/using.html#using-pathnames</a> Last login: Tue Jan 6 11:20:43 2015 from 10.0.2.2 Welcome to your Packer-built virtual machine. [vagrant@server ~]$ sudo su - [root@server ~]# yum install -y epel-release [root@server ~]# yum install -y docker-io</pre><p>So now I should have docker installed and checking the version should give you something similar to the output below.</p><pre>[root@server ~]# docker version Client version: 1.3.2 Client API version: 1.15 Go version (client): go1.3.3 Git commit (client): 39fa2fa/1.3.2 OS/Arch (client): linux/amd64 Server version: 1.3.2 Server API version: 1.15 Go version (server): go1.3.3 Git commit (server): 39fa2fa/1.3.2</pre><h3>Docker Primer</h3><p>I’m not going to do a command tutorial because the folks at docker have already provided a REALLY good one. <a href="https://www.docker.com/tryit/">Docker Tutorial</a>. Go ahead and give it a try. I will wait.</p><h3>Building a Dockerfile</h3><p>Now that you are familiar with the docker commands let’s build a Dockerfile.</p><pre>[root@server ~]# mkdir /nginx &amp;&amp; cd /nginx [root@server nginx]# vim Dockerfile</pre><p>A Dockerfile contains all the commands you normally execute to build a Docker image.</p><p>FROM debian:jessie</p><p>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.</p><p>The next thing I want to do is install some packages. To execute commands we are going to use the RUN directive.</p><pre>FROM debian:jessie RUN apt-get update &amp;&amp; apt-get install -y\ curl\ nginx-light\ &amp;&amp; apt-get clean</pre><p>I have curl and nginx-light installed in my image. Now let’s hammer out the rest of this Dockerfile.</p><pre>FROM debian:jessie RUN apt-get update &amp;&amp; apt-get install -y\ curl \ nginx-light\ &amp;&amp; apt-get clean RUN echo &quot;daemon off;&quot; &gt;&gt; /etc/nginx/nginx.conf EXPOSE 80 CMD [&quot;nginx&quot;, &quot;-c&quot;, &quot;/etc/nginx/nginx.conf&quot;]</pre><p>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.</p><p>Now we can build our image and run containers based on it.</p><pre>[root@server nginx]# docker build -t yarnhoj/nginx . Sending build context to Docker daemon 4.608 kB Sending build context to Docker daemon Step 0 : FROM debian:jessie ---&gt; 835c4d274060 Step 1 : RUN apt-get update &amp;&amp; apt-get install -y curl nginx-light &amp;&amp; apt-get clean ---&gt; Using cache ---&gt; 26d8200f733e Step 2 : RUN echo &quot;daemon off;&quot; &gt;&gt; /etc/nginx/nginx.conf ---&gt; Using cache ---&gt; 1f416c2eafe1 Step 3 : EXPOSE 80 ---&gt; Using cache ---&gt; bcdfdaa22a04 Step 4 : CMD nginx -c /etc/nginx/nginx.conf ---&gt; Using cache ---&gt; 3f257ba737b3 Successfully built 3f257ba737b3</pre><p>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.</p><p>Take a look at your images.</p><pre>[root@server nginx]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE yarnhoj/nginx latest 3f257ba737b3 2 days ago 150 MB debian jessie 835c4d274060 8 days ago 122.6 MB</pre><h3>Running a Container</h3><p>The docker run command takes several options. Let’s look at the complete command and talk about what it’s doing.</p><pre>[root@server nginx]# docker run -it -d --name web -p 80:80 yarnhoj/nginx 9714909758f650417c6d7e24ff2fea9e1355adc43eb1c178782171a8fe64bdb1 [root@server nginx]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9714909758f6 yanrhoj/nginx:latest &quot;nginx -c /etc/nginx 2 seconds ago Up 1 seconds 0.0.0.0:80-&gt;80/tcp web</pre><p>This command tells docker to do the following:</p><ul><li>-it -d — Run an keep STDIN open, Allocate a TTY, and run in detached mode.</li><li>-name web — Name my container web.</li><li>-p 8080:80 — Map port 80 on the host to port 80 in the container.</li><li>yarnhoj/nginx — The image name to start from.</li></ul><p>You can now run docker ps and see that your container is running.</p><h3>But is it really?</h3><pre>[root@server nginx]# curl localhost &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Welcome to nginx on Debian!&lt;/title&gt; &lt;style&gt; body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Welcome to nginx on Debian!&lt;/h1&gt; &lt;p&gt;If you see this page, the nginx web server is successfully installed and working on Debian. Further configuration is required.&lt;/p&gt; &lt;p&gt;For online documentation and support please refer to &lt;a href=&quot;http://nginx.org/&quot;&gt;nginx.org&lt;/a&gt;&lt;/p&gt; &lt;p&gt; Please use the &lt;tt&gt;reportbug&lt;/tt&gt; tool to report bugs in the nginx package with Debian. However, check &lt;a href=&quot;http://bugs.debian.org/cgi-bin/pkgreport.cgi?ordering=normal;archive=0;src=nginx;repeatmerged=0&quot;&gt;existing bug reports&lt;/a&gt; before reporting a new bug. &lt;/p&gt; &lt;p&gt;&lt;em&gt;Thank you for using debian and nginx.&lt;/em&gt;&lt;/p&gt; &lt;/body&gt; &lt;/html&gt;</pre><p>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.)</p><p>So the default index.html is kinda lame so as a parting shot let’s modify it with a standard hello world.</p><h3>Customizing nginx</h3><p>A couple of tasks to complete.</p><ul><li>Create the index.html in the same directory as our Dockerfile</li><li>Tell Docker to add that file to our image</li></ul><h3>Adding your own index.html</h3><pre>[root@server nginx]# echo &quot;Hello World&quot; &gt;&gt; index.html</pre><h3>Modify the Dockerfile</h3><pre>[root@server nginx]# vim Dockerfile FROM debian:jessie RUN apt-get update &amp;&amp; apt-get install -y\ curl\ nginx-light\ &amp;&amp; apt-get clean RUN echo &quot;daemon off;&quot; &gt;&gt; /etc/nginx/nginx.conf COPY index.html /var/www/html/ #&lt;------ADD THIS LINE EXPOSE 80 CMD [&quot;nginx&quot;, &quot;-c&quot;, &quot;/etc/nginx/nginx.conf&quot;]</pre><p>The copy command is going to do exactly what you think it will.</p><h3>Rebuild</h3><pre>[root@server nginx]# docker build -t yarnhoj/nginx . Sending build context to Docker daemon 4.608 kB Sending build context to Docker daemon Step 0 : FROM debian:jessie ---&gt; 835c4d274060 Step 1 : RUN apt-get update &amp;&amp; apt-get install -y curl nginx-light &amp;&amp; apt-get clean ---&gt; Using cache ---&gt; 26d8200f733e Step 2 : RUN echo &quot;daemon off;&quot; &gt;&gt; /etc/nginx/nginx.conf ---&gt; Using cache ---&gt; 1f416c2eafe1 Step 3 : COPY index.html /var/www/html/ ---&gt; 44d015a0947f Removing intermediate container 1f8161e6b2f3 Step 4 : EXPOSE 80 ---&gt; Running in e92a75c7742d ---&gt; 8c6a84dcb415 Removing intermediate container e92a75c7742d Step 5 : CMD nginx -c /etc/nginx/nginx.conf ---&gt; Running in e63b3eeae00a ---&gt; 50ad4aca5a95 Removing intermediate container e63b3eeae00a Successfully built 50ad4aca5a95</pre><p>You will probably 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.</p><p>Let’s stop our running nginx container and then launch the new one.</p><pre>[root@server nginx]# docker stop web &amp;&amp; docker rm web web web</pre><p>Now launch a new container.</p><pre>[root@server nginx]# docker run -it -d --name web -p 80:80 yarnhoj/nginx 4c094b64d0355ed3962f2e4a158cda5c2d6a3e63890a51f0c60ea98fbe1969c1 [root@server nginx]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4c094b64d035 yanrhoj/nginx:latest &quot;nginx -c /etc/nginx 3 seconds ago Up 2 seconds 0.0.0.0:80-&gt;80/tcp web [root@server nginx]# curl localhost Hello World</pre><p>Happy Hacking!</p><p><em>Originally published at </em><a href="http://blog.johnray.io/getting-started-with-docker"><em>blog.johnray.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec2aaa40577b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>