Needs : Docker 101

How to prepare this container environment ?

Task 1 (1/4)

Introduction

You can consider image as an template of container.

Docker image defnition :
A Docker image is made up of multiple layers. A user composes each Docker image to include system libraries, tools, and other files and dependencies for the executable code. Image developers can reuse static image layers for different projects. Reuse saves time, because a user does not have to create everything in an image.

Docker shares layer between containers to optimize storage and cache. In the production environment, you must know the size of the cache memory and purge it if necessary.

As you see, when you run an image for the first time container download all layers as compressed archive then extract info. But more layers there are, less apps start quickly.

Launch speed test containers :

time docker run -it sphinxgaia/training-sleep:v0.1

time docker run -it sphinxgaia/training-sleep:v0.1

Clean & Launch speed test containers :

docker container rm -f $(docker container ls -aq)

docker image rm sphinxgaia/training-sleep:v0.1

time docker run -it sphinxgaia/training-sleep:latest

As you see, container take a long time to startup (~ 0m25.420s) in first use case.
After that container uptime is near 0.636s the second time.
>
In the second use case, startup time is faster (~ 0m21.236s).
After that container uptime is near 0.635s the second time.

In production to accelerate and optimize container start-up and storage, the docker mechanism shares the existing identical layers between containers. But if you have too many layers, starting a new container will be less efficient because of the extraction time of all layers.

Logging Driver Environment ?

Task 1 (1/2)

Clean

docker container ls -a

Delete all

docker container rm -f $(docker container ls -aq)

clear

Introduction

As we see in the last scenario, a container generate logs on PID 1 in JSON format by default. Docker daemon support more logs type.

Please specify fluentd-* to Index name or pattern and press Create button.

Then, go to Discover tab to seek for the logs.

As you can see, logs are properly collected into Elasticsearch + Kibana, via Fluentd.

Logs and retention is very important in an ephemeral and elactic environment. Docker has native logs export in a multiple format.
So you can stream logs from files or export it directly from docker daemon (less storage)

Debugging Scenarios

Help

Katacoda offerings an Interactive Learning Environment for Developers. This course uses a command line and a pre-configured sandboxed environment for you to use. Below are useful commands when working with the environment.

cd <directory>

Change directory

ls

List directory

echo 'contents' > <file>

Write contents to a file

cat <file>

Output contents of file

Vim

In the case of certain exercises you will be required to edit files or text. The best approach is with Vim. Vim has two different modes, one for entering commands (Command Mode) and the other for entering text (Insert Mode). You need to switch between these two modes based on what you want to do. The basic commands are: