[Docker] Start the container as soon as possible

Environmental information

Docker Engine v18.09
RHEL7 with about 20GB of memory

File system used by the container

The related files of docker are in / var / lib / docker, and it runs on the default file system unless otherwise specified.

# df /var/lib/docker
..
/dev/mapper/rhel-var ... /var

Therefore, it is often heard that if you store too many images locally, the following will be tight.

/var/lib/docker/overlay2/

Container startup will be faster if continuous

A surprisingly unknown fact is that if you start containers in succession, the second time will be a little faster </ b>.

This is the difference between the Docker image being stored on disk and remaining in memory cache. If you want to feel it

time docker run ubuntu echo "hello"

Please start a container like this and hit commands that output hello as standard output in succession. It should be a little faster.

By the way, in the environment I'm playing, 0.8s becomes 0.6s, so it's an error, but if this changes clearly, the following measures are recommended.

Make / var / lib / docker a RAM disk

I will omit the explanation and how to make a RAM disk, but stop docker → copy / var / lib / docker with another name → prepare / var / lib / docker as a new file system → expand the copied files → docker When you start, it will always start at the speed that is in the cache.

However, due to the memory, it disappears every time you restart, so if you have the image locally, you need to take care of it. Also, if you do it, please note that if you do not do it in an environment with plenty of memory, the entire system will swap as a result.

Summary

By putting all Docker related files in memory, you can speed up the operation of the container environment. It also prevents the boot time from fluctuating, which essentially depends on whether the image is on disk or in memory </ b>. If there is a large time lag when starting continuously, a design that eliminates this shaking is important if time is used to determine startup failure.

that's all.

Recommended Posts