[ale] Does anyone have any experience actually running Docker?

Ted W. ted-lists at xy0.org
Thu Apr 6 23:13:47 EDT 2017


(This started as a quick response and turned in to a novel... I'm sending
it anyway. Please let me know if you have questions :) )

For background: The company I work for has used Docker pretty heavily in
a few environments, mostly internal facing, for a little over a year now
(maybe more in some areas). I have been pretty heavily involved with
research and implementation over the last 6 months as we ramp up our
production usage.

> I just want a MySQL container, a uWSGI/Django container, and an Nginx
> container, but how do I go about getting those?

Since this is a LUG mailing list, I'll assume you are using Linux. Docker
has official repositories[1] for most major distributions. If you're on
Mac, I highly recommend using the official Docker for Mac[2]. If you're on
Windows, you're on your own. I have no experience with options there :)
Docker development moves fast enough that you'll want to be on the latest
and greatest unless you have a specific reason not to be.

If you are just looking for something to work with that has the most done
"out of the box" as possible, look for work done by others on the
Docker Hub[3]. Let's use NGINX as an example. There is an official NGINX
container[4]. You would get this container using the command
`docker pull nginx` from a system that has Docker installed. Once
downloaded, you can see the image with the `docker images` command. You
can run it with the command `docker run -p 8080:80 nginx`. The -p flag
tells docker the port mapping. In this example, 8080 on your local
system would map to port 80 within the container. You can test this by
browsing http://localhost:8080 while the container is running. You'll
see your request logged in the screen running docker and you should see
the basic NGINX welcome page.

> How do I get my code into that container?

There are at least two ways to do this. Mount the content from the host
filesystem in to the container or include it in your custom image. Since
we're already talking about running an upstream container, I'll
show the volume option first:

`docker run -v /some/content:/usr/share/nginx/html:ro -p 8080:80 nginx`

Here we added the -v flag which mounts the /some/content directory on
your local system inside of the container under /usr/share/nginx/html
(docroot default in nginx) as read only. Now, if you navigate to
http://localhost:8080, you'll see the contents of /some/content. Note
that regular POSIX file permissions still apply meaning that the user
running NGINX in the container must have appropriate access to the files
you're trying to serve out. In the interest of time, I didn't bother to
find out exactly what user that was so I just made sure mode was at least
0644 on all files I intended to serve.

The examples above only cover a very small subset of what docker does
but it gives you an idea of how you could run a simple application like
NGINX. If you want to build your container, code and all, you need to
build a custom image. This is not as hard as it may sound. First, create
an empty working directory. Inside this working directory create two
files. The first is called "Dockerfile" containing:

  FROM nginx
  
  ADD ./index.html /usr/share/nginx/html/index.html

The FROM directive defines where we want to start. Here, we're starting
with the official NGINX image on Docker Hub. The ADD directive says
"Take this file from my local system and add it to the filesystem of the
container here."

The second file is named "index.html" :

  <html><body>Hello World!</body></html>

Be sure to `chmod 644` the index.html file so nginx can read it.
Now build your image:

  `docker build -t custom-nginx .`

The -t flag tags the image with a human readable name and the "." at the
end tells docker build to look for the Dockerfile in the current working
directory. Now, list your images with `docker images`. You should see a
new container listed called "custom-nginx". If you run that container
with `docker run -p 8080:80 custom-nginx` and browse to
http://localhost:8080, you should see the index.html served up.
There are many more parser directives available. See the documentation[5]
on Dockefiles for more information.

The way I think about the Dockerfil is like this. It defines a sequence
of actions to be taken during the creation of your container. Each new
directive you define adds a new layer to your image. It's not critical
to fully understand this now but later on when you have many directives
in your Dockerfile (for building a container running a completely custom
application, for example) the number of and ordering of these layers may
become important to the speed automated testing or storage efficiency on
your docker hosts.


[1] https://docs.docker.com/engine/installation/
[2] https://docs.docker.com/docker-for-mac/
[3] https://hub.docker.com/
[4] https://hub.docker.com/_/nginx/
[5] https://docs.docker.com/engine/reference/builder/

I hope this at least got you pointed in the right direction. These were
very simple examples. If you have more specific questions or would like
me to dive more in depth about anything here I am happy to do my best
and provide more information.

On Thu, Apr 06, 2017 at 09:52:44AM -0400, Kyle Brieden wrote:
> So I keep hearing just how awesome and wonderful and life-changing Docker
> is, but no one online seems to want to actually tell me how to USE it.  All
> the documentation I've found thus far either:
> 
> A) Makes assumptions about your environment, then fails to describe how to
> translate concepts to other environments
> B) Assumes you're already well versed in the basics, so starts at 80MPH
> C) Was written in 2014 or earlier
> 
> I understand the concept, and I appreciate *why* containers are
> fundamentally different than VMs, I just want to be able to actually
> "Dockerize" an application.
> 
> I just want a MySQL container, a uWSGI/Django container, and an Nginx
> container, but how do I go about getting those?  How do I get my code into
> that container?  Is anyone a docker expert or does anyone have a "0 to 45MPH
> docker crash course?"  I'm not looking for full out enterprise-ready
> production, here.  Just want to learn enough to get my app off the ground on
> my own docker host, then understand enough to push it up into something like
> AWS ECS or something.
> 
> Thanks!
> 
> ---
> Very respectfully,
> Kyle Brieden

> pub   rsa4096 2017-03-16 [SC]
>       BBDE95CDBEA858A23140071A7BFC2BC289C9D831
> uid           TxMoose <kyle at txmoose.com>
> sub   rsa4096 2017-03-16 [E]




> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://mail.ale.org/pipermail/ale/attachments/20170406/7b837e70/attachment.sig>


More information about the Ale mailing list