Feineigle.com - Docker Book, The

Home · Book Reports · 2024 · Docker Book, The

Published: October 14, 2024
Tags:  Docker



The book in...
One sentence:
The go-to docker book that provides the basics (for people like me) as well as a good introduction to the more advanced features available.

Five sentences:
The first ~40% is what I wanted, an introduction to Docker and its basic uses. The last ~60% of the book is more advanced, containing information about swarm, compose, clustering, building more complex multi-container applications, the API, and development. Overall I think docker (having barely used it) is a reasonable tool, but the fracturing of (too) many applications into "micro-services" I think leads to overall fragility within software development. In my case I am simply interesting in running docker on a small (NUC-like) server that can provide me with a simpler way to get up and running with SeaFile and maybe an internal website. For what I want, the first half of the book provided me with an understanding that allowed me to do everything I wanted to do.

designates my notes. / designates important. / designates very important.


Thoughts

Pages from pdf.

Exceptional Quotes


Table of Contents


· Chapter 01 - Introduction

page 19:
page 22:
page 23:
page 24:

• Docker Compose - which allows you to run stacks of containers to represent application stacks, for example web server, application server and database server containers running together to serve a specific application.

• Docker Swarm - which allows you to create clusters of containers, called swarms, that allow you to run scalable workloads.

page 26:

· Chapter 02 - Installing Docker

· Chapter 3 - Getting Started with Docker

page 62:
page 75:
page 79:
# Listing 3.37: Deleting all containers

sudo docker rm -f `sudo docker ps -a -q`

· Chapter 04 - Working with Docker images and repositories

page 83:
page 84:
page 94:
page 97:
page 98:
# Listing 4.21: Creating a sample repository

mkdir static_web
cd static_web
touch Dockerfile
# Listing 4.22: Our first Dockerfile

# Version: 0.0.1
FROM ubuntu:18.04
LABEL maintainer="james@example.com"
RUN apt-get update; apt-get install -y nginx
RUN echo 'Hi, I am in your container' \
    >/var/www/html/index.html
EXPOSE 80
page 99:
page 100:
# Listing 4.23: A RUN instruction in exec form

RUN [ "apt-get", " install", "-y", "nginx" ]
page 102:
# Listing 4.24: Running the Dockerfile

cd static_web
sudo docker build -t="jamtur01/static_web" .
page 103:
# Listing 4.25: Tagging a build

sudo docker build -t="jamtur01/static_web:v1" .
# Listing 4.26: Building from a Git repository

sudo docker build -t="jamtur01/static_web:v1" \
    github.com/turnbullpress/docker-static_web
page 104:
page 106:
# Listing 4.30: Bypassing the Dockerfile build cache

sudo docker build --no-cache -t="jamtur01/static_web" .
page 111:
# Listing 4.37: The docker port command

sudo docker port 6751b94bb5c0 80

> 0.0.0.0:49154
# Listing 4.39: Exposing a specific port with -p

sudo docker run -d -p 80:80 --name static_web_80 jamtur01 static_web nginx -g "daemon off;"
page 112:
# Listing 4.41: Binding to a specific interface

sudo docker run -d -p 127.0.0.1:80:80 --name static_web_lb jamtur01/static_web nginx -g "daemon off;"
# Listing 4.42: Binding to a random port on a specific interface

sudo docker run -d -p 127.0.0.1::80 --name static_web_random jamtur01/static_web nginx -g "daemon off;"
page 113:
# Listing 4.43: Exposing a port with docker run

sudo docker run -d -P --name static_web_all jamtur01/static_web nginx -g "daemon off;"
page 114:
# Listing 4.45: Specifying a specific command to run
sudo docker run -i -t jamtur01/static_web /bin/true
# Listing 4.46: Using the CMD instruction

CMD ["/bin/true"]
page 115:
# Listing 4.47: Passing parameters to the CMD instruction

CMD ["/bin/bash", "-l"]
page 117:
# Listing 4.51: Specifying an ENTRYPOINT

ENTRYPOINT ["/usr/sbin/nginx"]
# Listing 4.52: Specifying an ENTRYPOINT parameter

ENTRYPOINT ["/usr/sbin/nginx", "-g", "daemon off;"]
page 118:
# Listing 4.54: Using docker run with ENTRYPOINT

sudo docker run -t -i jamtur01/static_web -g "daemon off;"
page 119:
# Listing 4.55: Using ENTRYPOINT and CMD together

ENTRYPOINT ["/usr/sbin/nginx"]
CMD ["-h"]
page 120:
# Listing 4.56: Using the WORKDIR instruction

WORKDIR /opt/webapp/db
RUN bundle install
WORKDIR /opt/webapp
ENTRYPOINT [ "rackup" ]
# Listing 4.57: Overriding the working directory

sudo docker run -ti -w /var/log ubuntu pwd

> /var/log
# Listing 4.58: Setting an environment variable in Dockerfile

ENV RVM_PATH /home/rvm/
page 121:
# Listing 4.61: Setting multiple environment variables using ENV

ENV RVM_PATH=/home/rvm RVM_ARCHFLAGS="-arch i386"
# Listing 4.62: Using an environment variable in other Dockerfile instructions

ENV TARGET_DIR /opt/app
WORKDIR $TARGET_DIR
page 123:
# Listing 4.65: Using the USER instruction

USER nginx
page 124:
# Listing 4.67: Using the VOLUME instruction

VOLUME ["/opt/project"]
page 125:
# Listing 4.68: Using multiple VOLUME instructions

VOLUME ["/opt/project", "/data" ]
# Listing 4.69: Using the ADD instruction

ADD software.lic /opt/application/software.lic
page 126:
page 127:
page 128:
# Listing 4.73: Adding LABEL instructions

LABEL version="1.0"
LABEL location="New York" type="Data Center" role="Web Server"
page 129:
# Listing 4.75: Adding ARG instructions

ARG build
ARG webapp_user=user
page 130:
# Listing 4.76: Using an ARG instruction

docker build --build-arg build=1234 -t jamtur01/webapp .
page 131:
# Listing 4.78: Specifying a HEALTHCHECK instruction

HEALTHCHECK --interval=10s --timeout=1m --retries=5 CMD curl http://localhost || exit 1
page 133:
page 135:
# Listing 4.84: A new ONBUILD image Dockerfile

FROM ubuntu:18.04
LABEL maintainer="james@example.com"
RUN apt-get update; apt-get install -y apache2
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_RUN_DIR /var/run/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ONBUILD ADD . /var/www/
EXPOSE 80
ENTRYPOINT ["/usr/sbin/apachectl"]
CMD ["-D", "FOREGROUND"]

· Chapter 05 - Testing with Docker

page 157:
# Listing 5.9: Running our first Nginx testing container

sudo docker run -d -p 80 --name website -v $PWD/website:/var/www/html/website jamtur01/nginx nginx
page 158:
page 163:
# Listing 5.16: Dockerfile for our Sinatra container

FROM ubuntu:18.04
LABEL maintainer="james@example.com"
ENV REFRESHED_AT 2016-06-01
RUN apt-get update -yqq; apt-get -yqq install ruby ruby-dev build -essential redis-tools
RUN gem install --no-rdoc --no-ri sinatra json redis
RUN mkdir -p /opt/webapp
EXPOSE 4567
CMD [ "/opt/webapp/bin/webapp" ]
page 174:
page 175:
page 176:
page 177:
page 178:
# Listing 5.43: Docker iptables and NAT

sudo iptables -t nat -L -n
page 180:
page 181:
page 182:
# Listing 5.49: Creating a Docker network

sudo docker network create app
page 183:
page 184
# Listing 5.52: Creating a Redis container inside our Docker network

sudo docker run -d --net=app --name db jamtur01/redis
page 186:
# Listing 5.54: Linking our Redis container

cd sinatra
sudo docker run -p 4567 --net=app --name network_test -t -i jamtur01/sinatra /bin/bash
root@305c5f27dbd1:/#
# Listing 5.56: DNS resolution in the network_test container

root@305c5f27dbd1:/# nslookup db
Server: 127.0.0.11
Address:127.0.0.11#53

Non-authoritative answer:
Name: db
Address: 172.18.0.2
page 187:
# Listing 5.57: Pinging db.app in the network_test container

root@305c5f27dbd1:/# ping db.app
PING db.app (172.18.0.2) 56(84) bytes of data.
64 bytes from db (172.18.0.2): icmp_seq=1 ttl=64 time=0.290 ms
page 188:
# Listing 5.58: The Redis DB hostname in code

redis = Redis.new(:host => 'db', :port => '6379')
page 190:
page 192:
page 193:

· Chapter 06 - Building services with Docker

page 226:
page 227:
# Listing 6.11: Creating an Apache container
sudo docker run -d -P --volumes-from james_blog jamtur01/apache
09a570cc2267019352525079fbba9927806f782acb88213bd38dde7e2795407d
page 231:
page 264:
# Listing 6.62: Using docker kill to send signals
sudo docker kill -s <signal> <container>

· Chapter 07 - Docker Orchestration and Service Discovery

page 267:
page 317:

· Chapter 08 - Using the Docker API

page 332:
page 333:
page 334:
# Listing 8.1: Querying the Docker API locally
curl --unix-socket /var/run/docker.sock http:/info
{"ID":"PH4R:BT7H:44F6:GQGP:FS2O:7OZO:HQ2P:NSVF:MK27:NBGZ:N3VP:
    K2O5","Containers":3,"ContainersRunning":3,"ContainersPaused"
    :0,"ContainersStopped":0,"Images":3,"
. . .
}

· Chapter 09 - Getting help and extending Docker