The Overhead of Docker Run
First published on Medium on 10/11/2016.
We use Docker a lot. Like a lot, lot. While we love it for a lot of things, it still has a lot of room for improvement. One of those areas that could use improvement is the startup/teardown time of running a container.
Table of Contents
Related Reading: The pros-and-cons of docker
Achieve Cloud Elasticity with Iron
Speak to us to find how you can achieve cloud elasticity with a serverless messaging queue and background task solution with free handheld support.
To test the overhead of running a Docker container, I made a script that compares execution times for various docker run options vs not using Docker at all. The script that I’m running is a simple hello world shell script that consists of the following:
echo "Hello World!"
The base Docker image is the official Alpine linux image plus the script above.
4 Things to Compare
- As a baseline, the first measurement is sans Docker. This is just running the hello.sh script directly.
- The second measure is just docker run IMAGE.
- The third measure adds the “rm” flag to remove the container after execution.
- The final one is to use docker start instead of run, so we can see the effect of reusing an already created container.
Docker for Mac
Server Version: 1.12.2-rc1
Running: ./hello.sh avg: 5.897752ms Running: docker run treeder/hello:sh avg: 988.098391ms Running: docker run — rm treeder/hello:sh avg: 999.637832ms Running: docker start -a reuse avg: 986.875089ms
(Note: looks like using Ubuntu as a base image is slightly faster than Alpine, in the 10–50ms range).
Iron.io Serverless Tools
Speak to us to learn how IronWorker and IronMQ are essential products for your application to become cloud elastic.
Docker on Ubuntu
Server Version: 1.12.1
Running: ./hello.sh avg: 2.139666ms Running: docker run treeder/hello:sh avg: 391.171656ms Running: docker run — rm treeder/hello:sh avg: 396.385453ms Running: docker start -a reuse each: 340.793602ms
As you can see from the results above, using Docker adds nearly a full second to the execution time of our script on Mac and ~390ms on Linux (~175x slower than running the script without Docker).
Now, this may not be much of an issue if your script/application runs for a long period of time, but it is certainly an issue if you run short-lived programs.
Try it yourself
Feel free to try running the script on your system and share the results! You can find everything you need here:https://github.com/treeder/dockers/tree/master/hello
Just clone that repo, cd into the hello directory and run:
go run time.go
Unlock the Cloud with Iron.io
Find out how IronWorker and IronMQ can help your application obtain the cloud with fanatical customer support, reliable performance, and competitive pricing.
Leave a Comment