Share resources managed by the host OS kernel with guest processes.
Kernel needs to address security concerns and provide isolation on visibility, access and use of hsared resources.
Linux cgroups control access and use of resources, provide resource usage monitoring and are dynamic and persistent.
Create a hierarchy:
mkdir /cgroup/cpu_and_memList all subsystems:
lssubsys -am cpu cpuset memoery net_cls ns cpuacct devices freezer blkio7Mount the hierarchy and attach subsystems:
mount -t cgroup -o cpu,cpuset,memory cpu_and_mem /cgroups/cpu_and_memRemount the hierarchy and include subsystem cpuacct:
mount -t cgroup -o remount,cpu,cpuset,cpuacct,memory cpu_and_mem /cgroup/cpu_and_memUnmount the hierarchy:
umount /cgroup/cpu_and_memCreate a child in the hierarchy:
mkdir /cgroup/cpu_and_mem/cgroup1Configure a cgroup setting:
echo 0-1 > /cgroup/cpu_and_mem/cgroup1/cpuset.cpusMove a process into a cgroup:
echo 1701 > /cgroup/cpu_and_mem/cgroup1/tasksStart a process in a cgroup:
echo $$ > /sys/fs/cgroup/cpu_and_mem/cgroup1/tasks && dd if=/dev/urandom | bzip2 -9 >> /dev/nullFind a process:
ps -0 cgroupFind a process with known PID:
cat /proc/PID/cgroupFind subsystems:
cat /proc/cgroupsLinux namespaces provide:
Linux namespaces:
Namespaces are used to implement containers.
Linux Native Container Technology (LXC) is a technology enabled via kernel features
chrootOpen source software engine to commoditize Linux Containers.
A container is a runnable instance of an image and can be created, run, stopped, moved or deleted.
Automatically added by default:
/ as default user is root/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/User specified variables are added when running a container
docker run -e LAB=DockerSend envrionment variable from one container to another one at runtime by establishing a unidirectional link.
docker run -d --name DB my_db
docker run -d --link DB --name WEB my_appDocker automatically exposes a set of environment variables of the form:
<name>_PORT_<port>_<protocol>In the above case it might be:
DB_PORT=tcp://172.12.0.2:27017
DB_PORT_27017_TCP_ADDR=172.12.0.2
DB_PORT_27017_TCP_PORT=27017
DB_PORT_27017_TCP_PROTO=tcpAn image is a collection of read-only content for creating a container.
Image layers are stored in the Docker host local storage area (typically in /var/lib/docker).
Docker Services appear to be a single application to the consumer and allow to scale collaborating containers across multiple Docker daemons. A service defines its desired state (resilience, elasticity).
Recommended, portable way to create Docker images.
FROM existing image
RUN command
ADD file from host machine
EXPOSE a port by default
CMD run command by default on start if not overridden
ENTRYPOINT always run command on start
Nginx example:
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y nginx
EXPOSE 80 443
ENTRYPOINT ["nginx"]
CMD ["-g", "daemon off;"]Build the image for the folder with the Dockerfile:
docker build -t <my-container-image-name>Docker registry is open source code to store images. A public Docker registry is provided: Docker Hub.
Registry -> Repositories -> Images
Image naming convention: <user-name>/<image-name>:<tag>
Commands:
docker login
docker pull <image-name>:<tag>
docker tag <tag> <image-name>
docker push <image-name>:<tag>
docker search <keyword>Simon Anliker Someone has to write all this stuff.