-
Michael Marsh authoredMichael Marsh authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
README 3.40 KiB
We're going to be using docker in this course, though not as intensively as git. Still, it's worth taking some time to familiarize ourselves with it, especially since you're unlikely to be familiar with it. What is docker? You can think of it like a lightweight VM. It's really considerably different, because it uses the host processor, memory, network stack, etc., without creating virutal hardware. We can throw around terms like user-level filesystems, process groups, and network namespaces, but the important part is that you can run a self-contained guest Linux OS within another host Linux OS, with applications and all of their dependencies. The guest can only see the resources given to it by the host, so it provides some (minimal) level of security. It also means we can start a process from a known-clean state, so we have repeatability. Exercise 1: Docker Images ========================= Let's start with the concept of an *image*. This is the self-contained guest Linux OS, which is configured to automatically run some process when it starts. Nothing is running in it -- you can think of it like a hard drive. The easiest way to get an image is to *pull* it from a *registry*. Docker has a default registry built in. Our VM is running Ubuntu 16.04, and it turns out there's an image available with this OS on it! Here's the command to run: docker pull ubuntu:16.04 Let's go through this command. "docker" is, of course, the utility we're using. The "pull" command tells us that we want to get something from a registry. In this case, we're getting the "ubuntu" image from the default registry. If we just left it at this, we'd get *all* of the ubuntu variants. Instead, we add ":16.04". That tells docker we only want one image, and it's the one with the *tag* "16.04". When the command completes, try running docker image list You should see something like: REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 16.04 2a4cca5ac898 28 hours ago 111MB Most of this should be fairly self-explanatory. The image ID is another hexadecimal number, like with git, but it's clearly not a SHA-1 hash. It really doesn't matter what it is, other than a unique identifier for this image. We can do a few things with this image, aside from running it. Try the following: docker tag ubuntu:16.04 my_ubuntu docker image list Note that we now see the same image ID twice, but with different names. By default, a repository (the tagless part of an image name) is tagged as "latest" if you don't specify one. Let's try specifying a tag, though: docker tag ubuntu:16.04 foo:bar docker image list The results should not be surprising. We can quickly build up a lot of images we don't want anymore, so it's good to know how to clean these up. Let's get rid of our new tagged images: docker rmi my_ubuntu:latest foo:bar docker image list A common problem is that we'll end up reusing an old tag, leaving an image with no repository:tag name. These show up as "<none>:<none>". We can get rid of all of these with the following bash one-liner: docker images -a | grep none | awk '{print $3}' | xargs docker rmi For the curious, feel free to read the man pages for awk and xargs. This is not going to be essential information for this course, though. Exercise 2: Running an Image in a Container ===========================================