Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
docker-tutorial
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Alan Marsh
docker-tutorial
Commits
3f6d5752
Commit
3f6d5752
authored
7 years ago
by
Michael Marsh
Browse files
Options
Downloads
Patches
Plain Diff
starting docker tutorial
parents
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README
+89
-0
89 additions, 0 deletions
README
with
89 additions
and
0 deletions
README
0 → 100644
+
89
−
0
View file @
3f6d5752
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
===========================================
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment