|
| 1 | + |
| 2 | + |
| 3 | +Introducing Docker |
| 4 | +================== |
| 5 | + |
| 6 | +[Docker](www.docker.com) has some similarities with Virtualization Technologies: |
| 7 | + |
| 8 | +- both involve the creation of reuseable images |
| 9 | +- both involve running one or more instances of an image on a Host machine |
| 10 | +- images can be transported from one Host to another and run successfully |
| 11 | +so long as the hosting software is installed |
| 12 | + |
| 13 | +Docker images differ from Virtualization images in many important ways. |
| 14 | + |
| 15 | +- They are 5-10 times smaller |
| 16 | +- They depend on and use much more of the host linux resources |
| 17 | +- They are less secure |
| 18 | +- Instances are called Containers |
| 19 | +- Containers can be instantiated and run within seconds |
| 20 | +- Containers can be plugged in to the Host tty, STDIN, STDOUT, and STDERR |
| 21 | + |
| 22 | +The primary difference between a Docker image and a VM image is tied to |
| 23 | +a philosophical difference. |
| 24 | + |
| 25 | +VM images are created to host an entire machine architecture which is run as if it were its own machine, completely oblivious to its host. |
| 26 | + |
| 27 | +Docker images are designed to host a single application and its dependencies. They are designed to run on the host as if natively installed. To compose a pipeline, you use or create docker images for each application required, and run containers from the host more or less hooked in to the host, similar to the way you would run a natively installed application. |
| 28 | + |
| 29 | +Docker Ecosystem |
| 30 | +---------------- |
| 31 | + |
| 32 | +**Docker Machine** |
| 33 | + |
| 34 | +Host systems must install and run the Docker daemon. The daemon can only run on a modern (version created within the last 2 years) Linux Kernal. Almost all flavors of Linux (Fedora, Redhat, Ubuntu, Debian) use the Linux Kernal, and can host the daemon on them natively. Some flavors of \*Nix (Mac OSX in particular), do not use the Linux Kernal. They must run the docker daemon inside a VirtualMachine built on one of the Linux flavors with a modern kernal. This can introduce a bit more complexity, but it also introduces the powerful concept of using external docker hosts 'in the cloud'. |
| 35 | + |
| 36 | +The docker daemon runs a web service in the background and listens to special ports for requests to manage docker images and containers. It provides a REST interface API that can be used by any client. Typically, it uses an encrypted connection called TLS, which is a standard system used by many network client-server communications. TLS requires that each client generate an encrypted certificate (not the same as used by GitHub) to be used when they communicate with the service. The primary client that uses the REST interface is the docker commandline interface. |
| 37 | + |
| 38 | +The [docker-machine](https://docs.docker.com/machine) command automates the process of getting a docker host running on any computer with a supported Virtualization system (Virtualbox and VMware are supported). It makes it much easier to get Docker up and running if you do not have Systems Administration expertise. It does this by: |
| 39 | + - downloading a special VM image for a specified VM management system preconfigured to host and run the docker daemon |
| 40 | + - generating TLS certificates |
| 41 | + - starting and stopping the VM |
| 42 | + - Providing an easy way to configure the Environment needed by the Docker commandline interface (see below) |
| 43 | +The docker-machine command can also be used to create docker machines on many cloud [hosting systems](https://docs.docker.com/machine/#using-docker-machine-with-a-cloud-provider), which may be attractive to those wanting to purchase more powerful compute environments than are provided by their own machine, or institution. |
| 44 | + |
| 45 | +**Docker** |
| 46 | + |
| 47 | +The [docker commandline interface](https://docs.docker.com/reference/commandline/cli/) is written in the Go programming language. There are versions available for every known operating system (even Windows 10!). It is designed to interface with the Docker Machine daemon over the network using its REST interface. By compartmentalizing the docker interface from the docker machine, it is possible to use the same docker command to interface with a docker machine running anywhere on the network. |
| 48 | + |
| 49 | +The client must run in the context of a special set of Environment variables: |
| 50 | +* DOCKER_TLS_VERIFY (1 if using TLS, default) |
| 51 | +* DOCKER_CERT_PATH (path to TLS certificate if using TLS) |
| 52 | +* DOCKER_HOST (url and port to the Docker Host daemon service) |
| 53 | + |
| 54 | +The docker commandline interface provides the full set of tools needed to create and manage docker images and image container instances. |
| 55 | + |
| 56 | +* pull images from a Docker Registry (it knows about the Official Docker Registry by default) |
| 57 | +* push images to a Docker Registry (requires login) |
| 58 | +* list images |
| 59 | +* build images from a build context (more about this tomorrow) |
| 60 | +* remove images |
| 61 | +* tag images (acts like an alias) |
| 62 | +* run container instances of images |
| 63 | +* list containers |
| 64 | +* start and stop existing container instances (background only) |
| 65 | +* pause/unpause existing containers (foreground and background) |
| 66 | +* kill a running container (stop is preferred but kill can be used to stop a runaway container process) |
| 67 | +* rm stopped/killed container instances |
| 68 | +* inspect container instances (running or stopped) |
| 69 | +* Dump the log (STDOUT) from a running container |
| 70 | +* save and load a tar file of an image (can be used instead of a registry to move docker images from one machine to another) |
| 71 | +* exec a command in a running container (allows you to interact with, and change the state of a running container) |
| 72 | + |
| 73 | +There are many arguments that you can provide to the [Run](https://docs.docker.com/reference/run/) command: |
| 74 | +* container naming (docker provides default names to all containers, sometimes humorous), you can specifically name a container at run time |
| 75 | +* interactivity mode (interactive or daemon mode) |
| 76 | +* attach the host tty (we will demonstrate this) to an interactive container |
| 77 | +* mount local directories to the container file system |
| 78 | +* connect one container to another container to make a private network between them |
| 79 | +* mount volumes from other, special containers, called volume containers, to the container file system |
| 80 | +* set the user, group, working directory to be used inside the container |
| 81 | +* set environment variables |
| 82 | +* override the default entrypoint or command (more on this tomorrow) |
| 83 | +* connect host and container STDIN, STDOUT, and STDERR |
| 84 | +* expose container ports to the host |
| 85 | + |
| 86 | +**Docker Registry** |
| 87 | + |
| 88 | +Docker has hosted a worldwide [Registry](https://registry.hub.docker.com/) of Docker images. Anyone with docker can share their own images with the world. Images shared on the Docker Registry cannot be private. It is possible to [host your own registry](http://docs.docker.com/registry/deploying/). |
| 89 | + |
| 90 | +The Docker commandline tool is preconfigured to know about and use the official |
| 91 | +Docker Registry. |
| 92 | + |
| 93 | +- docker pull i will pull the image i down onto your host |
| 94 | +- docker run i will pull the image i down if it is not present, and then run a container of i |
| 95 | + |
| 96 | +Lesson Plan |
| 97 | +----------- |
| 98 | + |
| 99 | +- install docker-machine and docker |
| 100 | +- explore the Docker Registry |
| 101 | +- run some docker images |
| 102 | + - with and without docker pull |
| 103 | + - with and without local storage |
| 104 | + - with exposed ports |
| 105 | + - connected to other container systems/services |
| 106 | +- inspect information about containers |
| 107 | +- inspect the log from running containers |
| 108 | +- remove images |
| 109 | +- remove containers (with volumes) |
| 110 | + |
| 111 | +Resources |
| 112 | +--------- |
| 113 | +- https://www.docker.com/ |
| 114 | +- https://docs.docker.com/machine/ |
| 115 | +- https://docs.docker.com/compose/ |
| 116 | +- https://docs.docker.com/userguide/ |
| 117 | +- https://docs.docker.com/reference/commandline/cli/ |
| 118 | +- https://registry.hub.docker.com |
| 119 | +- https://registry.hub.docker.com/u/tutum/hello-world/ |
0 commit comments