Why this Matters
Traditional monolithic architectures are hard to scale. As an application's code base grows, it becomes complex to update and maintain. Introducing new features, languages, frameworks, and technologies becomes very hard, limiting innovation and new ideas.
Within a microservices architecture, each application component runs as its own service and communicates with other services via a well-defined API. Microservices are built around business capabilities, and each service performs a single function. Microservices can be written using different frameworks and programming languages, and you can deploy them independently, as a single service, or as a group of services.
Introduction to the Build Process
In this introduction we'll cover an overview of Docker images, how docker uses layers to build images, and an introduction to the Dockerfile
used by "docker build" command to create images. (Note case is important here, the "D" is upper case, and the rest in lower case).
The Dockerfile contains all the instructions needed to build an image, and it must be
in the root of the project directory.
Building an image is done with the "docker build" command. Docker looks for a Dockerfile in the base of the directory.
Use the -t option to name your image. The image is only available if the build completes successfully.
Previously built layers will be reused. The -f flag can be used to specify a different Dockerfile.
Every container starts from an image. There are many images in the docker registry: hub.docker.com
to help developers get started.
Layers are Shared
Images are Shared
What are the benefits of base images?
- Don't Repeat Yourself
- Containers should be ephemeral
- Using a base system allows for inheritance
- Base your images on official images to allow for reuse
Working with Files
Source paths are always relative to the Dockerfile project directory.
You cannot use source files outside the Dockerfile project directory.
Commands: WORKDIR, COPY, ADD. It is recommended to always use absolute paths with WORKDIR.
COPY src dest
....you can also use JSON format:
COPY ["src", "dest"]
COPY test.txt /data/test.txt
The destination directory or parent directories don't have to exit before COPY command.
WORKDIR. Paths that do not end "/" are treated as a regular file. Paths that end in "/"
is treated as a directory.
1> docker build -t dem0 .
Sending build context to Docker daemon 3.072kB
Step 1/2 : FROM debian:stretch
stretch: Pulling from library/debian
219d2e45b4af: Pull complete
Status: Downloaded newer image for debian:stretch
Step 2/2 : COPY test.txt /data/test.txt
Removing intermediate container 6da02b3061fa
Successfully built 7797f76796b5
Successfully tagged dem0:latest
0> docker run --rm -it dem0
root@a8de718353f0:/# cd /data
root@a8de718353f0:/data# ls -la
drwxr-xr-x 2 root root 4096 Oct 1 21:31 .
drwxr-xr-x 28 root root 4096 Oct 1 21:32 ..
-rw-r--r-- 1 root root 17 Oct 1 21:29 test.txt
root@a8de718353f0:/data# cat test.txt
I am a test file
command works like COPY
with additional features. For example, it can fetch files from
the internet and copy them to the destination. If neither the source url or the destination end with a slash,
the file is downloaded and copied to the destination. If both the source url and the destination end with a slash, the
downloaded file is copied into the destination directory with that name.
https://root/something/ /dest/ .... it would be placed in /dest/something.
can unpack local tar files. The files can be compressed with gzip, bzip2, and xz. This feature does not
work for URLs, only local files.
Docker cmdline examples:
0> docker container run -it --name=bb busybox:1.26
Unable to find image 'busybox:1.26' locally
1.26: Pulling from library/busybox
27144aa8f1b9: Pull complete
Status: Downloaded newer image for busybox:1.26
/ # ps aux
PID USER TIME COMMAND
1 root 0:00 sh
5 root 0:00 ps aux
/ # ls -la
Mem: 2111880K used, 1741328K free, 5892K shrd, 267036K buff, 1390336K cached
CPU: 0.0% usr 0.0% sys 0.0% nic 100% idle 0.0% io 0.0% irq 0.0% sirq
Load average: 0.00 0.00 0.00 2/223 8
PID PPID USER STAT VSZ %VSZ CPU %CPU COMMAND
1 0 root S 1204 0.0 0 0.0 sh
8 1 root R 1196 0.0 0 0.0 top
/ # Crt-D (exit)
130> docker attach bb
You cannot attach to a stopped container, start it first
1> docker start bb
0> docker attach bb
Show Docker Disk Usage: system df
1> docker system df
|TYPE || TOTAL || ACTIVE || SIZE || RECLAIMABLE|
|Images || 17 || 9 || 3.436GB || 2.515GB (73%)|
|Containers || 16 || 5 || 177.5MB || 166MB (93%)|
|Local Volumes || 5 || 3 || 74.92MB || 106.7kB (0%)|
Docker Reading List
Evolution of Containers - Docker, Solaris Zones, BSD Jails and more
The Docker Story
What is Docker by Docker
Who is using Docker and How
Docker vs Vagrant