The document provides an overview of Docker containers and images. It discusses how containers isolate processes and resources, how they are named and networked, and how to attach environment variables and volumes. It also explains how images are built in layers and stored in registries, and recommends tools for managing images, logs, and using Docker with configuration management.
9. Containers: Names
Containers can be referenced by:
Full ID: <64 character random>
bd7d7e9c92c78f009500504abf5260396755cd9310980b980deaeacadee87dc4
Short ID: <12 character random> bd7d7e9c92c7
Random Friendly Name: <adjective-scientist> drunk-einstein
OR
Assigned Name: --name wp-mysql
14. Containers: Attached vs Detached
Attached: Monitor output directly. Use ctrl-c/ctrl-d to stop running process.
--rm flag will remove the container when process ends.
Detached use docker ps/logs to monitor, docker start, stop to control.
This will not clean up after its self – use docker rm
What Docker really is, is a set of tools for isolating Applications and their dependencies.
Docker really shines with applications that do not require persistent data.
Containers can be referenced by:
.
Full ID: 64 character random string
Short ID: the first 12 character of the 64 character string
.
Random Friendly Name which consists of an adjective followed by a scientist
OR
A name assigned at runtime with --name
.
Container names must be unique. If you try to duplicate names docker will complain.
When we talk about docker, we are usually talking about containers.
Containers consist of all the libraries and dependencies that are required by the application to run.
They utilize the network,filesystems and kernel of the host system. This makes them light weight in comparison to other VMs
Containers run one process
.
That process can spawn more processes
.
When parent process ends the container stops
.
Here we have a side by side comparison of a container running apache vs a full vm running apache.
.
You can see that containers don&apos;t have the overhead of a full init, cron, syslog, or other standard processes. This makes containers very memory efficent.
Containers can be referenced by:
.
Full ID: 64 character random string
Short ID: the first 12 character of the 64 character string
.
Random Friendly Name which consists of an adjective followed by a scientist
OR
A name assigned at runtime with --name
.
Container names must be unique. If you try to duplicate names docker will complain.
By default containers use a bridged interface.
.
This is automatically configured by the docker daemon - docker0.
.
Containers will be assigned an unused private network address space – usually on the 172. network.
.
Containers assigned to the same network can talk directly to each other.
.
The host will route packets to the outside world so you can get out to your network.
Containers use Kernel Namespaces to provide isolation from other running continers.
The host system has access to all the container and their processes.
These variables are exported to the shell environment at container runtime.
.
You can use these variables to configure your application.
Containers can be linked for convenient inter-container communication.
.
The container requesting the link is provided info
about available services on the linked from
Container via environmental variables.
.
Explain slide
If containers need persistent data, containers can
mount directories from host system or shared from
other containers.
Attached containers are run interactively in the Foreground.
.
This is useful for debugging or running a development instance.
.
Attached containers have the option to remove themselves after completion if you run with the –rm flag.
.
Detached or daemonized containers are run in the background.
.
This is normally how containers run on a server.
.
You can attach to detached containers by using the docker attach command if they were run with the –it flag
.
Detached containers do not have the option to clean up after themselves. This is so you can troubleshoot if things go wrong.
.
You can detach from a container without stopping the running process with Ctrl-p followed by Ctrl-q
Really when working with detached containers I suggest not attaching but following the output with the docker logs command.
.
Container output can be followed with
docker logs -f &lt;container&gt;.
Images are saved container states.
Images use a union filesystem. A union filesystem consists of a series of read-only layers with the top layer being read-write.
.
Images are built in layers. Starting with a base image, each command in the build process adds an additional layer.
.
This allows images and containers to share the identical pieces making storage really efficient.
You can centrally save your images and distribute them with a docker registry.
.
Docker uses git like commands for managing images – push, pull and tag.
.
Docker.com provides free public and paid private hosting.
.
You can also host your own docker registry.
.
The softare is conveniently avalible as a public docker image on docker.com: docker-registry