liveBook · Manning

Docker

As explained in Kubernetes for Developers

Docker is a platform and toolset for building, packaging, and running containers.

An application that works on a developer’s laptop may fail elsewhere because the other machine lacks its dependencies or has a different configuration. Docker lets you package the application and its dependencies into a container image, then run a container from that image. Developers can work on separate projects without installing every project’s dependencies on their host machine. section 2.0 section 1.1.1

An image is the artifact you download or build; a container is a running instance created from it. Docker can run these instances locally. A Dockerfile records how to prepare an application image, replacing setup instructions that otherwise depend on scripts or memory. Containers also let applications share a host while keeping their environments isolated, with less overhead than full virtual machines. section 2.1.2 section 2.0

Try an isolated shell

Run `docker run -it ubuntu bash`. Docker downloads the Ubuntu image, creates a container, and opens an interactive shell inside it. Installing Python there changes the container environment, not the host. After exiting, use `docker ps -a` to find the stopped container; `docker start` and `docker attach` let you return to it. section 2.1.2

Listing 2.12 Chapter02/2.1.7_CompiledCode/Dockerfile
FROM openjdk
COPY . /app
WORKDIR /app
RUN javac Hello.java   #1
CMD java Hello
#1 The compile command

For code that needs compilation, this Dockerfile starts from an OpenJDK image, copies the application, sets a working directory, compiles it, and specifies the command to run. Docker can therefore build the program inside the image rather than requiring a locally compiled binary. section 2.1.7

Containerizing an application is a prerequisite for deploying it with Kubernetes, but the tools have different jobs here: Docker supports local building and running, while Kubernetes schedules containers across nodes and manages their lifecycle through a container runtime. Kubernetes configuration names images; the resulting container instances are created at run time and are ephemeral. section 2.0 section 2.1.2 section 3.1.1

How Kubernetes for Developers covers it

How deep it goes
Works through local container commands and a compiling Dockerfile, but does not detail Docker’s internal implementation.
Examples
Uses an interactive Ubuntu shell, Python commands, and a Java application compiled in a Dockerfile.
What it assumes
Introduces images and containers through a shell walkthrough while expecting the reader to install Docker and run commands.
What you can do after
Build it from scratch with a Dockerfile, then run and inspect containers using Docker commands.
How it connects
Connects Docker to container images, Dockerfiles, virtual machines, and Kubernetes.

Also explained in

Compare how 26 books explain Docker →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes for Developers. The section links point to the parts of the book it draws on.