Docker
Why Docker
With Docker, developers can build any app in any language using any toolchain. “Dockerized” apps are completely portable and can run anywhere - colleagues’ OS X and Windows laptops, QA servers running Ubuntu in the cloud, and production data center VMs running Red Hat.
Developers can get going quickly by starting with one of the 13,000+ apps available on Docker Hub. Docker manages and tracks changes and dependencies, making it easier for sysadmins to understand how the apps that developers build work. And with Docker Hub, developers can automate their build pipeline and share artifacts with collaborators through public or private repositories.
Docker helps developers build and ship higher-quality applications, faster.
Installation
To install docker, follow the guide appropriate for you operating system at: Get Docker.
You may need to contact the IT department (helpdesk.jax.org or x1414) to have it installed for you.
Quickstart Commands
Lifecycle
* docker build build an image from a Dockerfile
* docker build -t <tag> build and image and tag it
* docker create creates a container but does not start it.
* docker rename allows the container to be renamed.
* docker run creates and starts a container in one operation.
* docker rm deletes a container.
* docker run --rm will remove the container after it stops.
* docker update updates a container's resource limits.
Starting and Stopping
* docker start starts a container so it is running.
* docker stop stops a running container.
* docker restart stops and starts a container.
* docker pause pauses a running container, "freezing" it in place.
* docker unpause will unpause a running container.
* docker wait blocks until running container stops.
* docker kill sends a SIGKILL to a running container.
* docker attach will connect to a running container.
What is a Docker Image?
Every Docker image references a group of read-only layers representing filesystem differences. In order to create a container from these, the layers are stacked on top of each other, forming a base for the container’s root filesystem.
Containers and Images
What benefit do container provide over images? Since each container has its own thin writable container layer to store data changes, multiple containers can access the same underlying image and still have their own data state.
Extending an Image
In order to create an image based off an existing image, or a base image provided by Docker, we need to use a Dockerfile. By reading the instructions from a Dockerfile, a text document that contains all the commands a user could call on the command line to assemble an image, Docker can build images automatically.
To build an image from a Dockerfile, we use the docker build command, followed by the path to the build context, usually the current directory. Say we’re building an ubuntu image that has a custom ssh banner. In our project directory we’ve got two files: our completed Dockerfile, and a custom issue.net file. To build our new Docker Image, we run docker build with the -t flag to give it a tag:
What happens during a build?
The docker build command builds Docker images from a Dockerfile and a “Context.” A build context is the directory passed to the command, all files it contains, and all subfolders and their files. During a build, this context gets tar’d and sent to the docker daemon where the daemon is free to use it during the build process. That’s not to say that the entirety of this data is the included in your image, it isn’t. Only data that is explicitly added to your image in your Dockerfile will be available in the final image build.
Tutorial
Examples
- Examples
- Best practices for writing Dockerfiles
- Michael Crosby has some more Dockerfiles best practices / take 2.
- Building Good Docker Images / Building Better Docker Images
- Managing Container Configuration with Metadata
Next Steps
Official Images
The docker hub and docker store provide an enormous resource of community and official images; this is usually the best place to start. If millions of people are using an image of a Postgresql server, it would have to be under especially interesting circumstances that you would have to create your own Postgresql image.
Start Simple
Try taking the base debian:jessie image and using it to create a custom docker image. Try taking a tutorial you know well, and getting it to run in a docker container.
Dockerfile Best Practices Docekr Builder