Docker startup time
Solution 1:
The overhead time is most likely being spent creating and removing namespaces. To work out where the time is spent, you can run your container in different ways.
First, eliminate the sudo command. Login as root, sudo -s
, and run commands from there.
Next try splitting the run into separate create and start steps. This will let you know if the time is spent creating the container or running it:
$ time docker create --cap-add SYS_ADMIN -itd \
--memory=100000k --memory-swap=100000k \
-w /tmp -v /home/asd:/tmp my_image
$ time docker start -ai $(docker ps -ql)
Since you run your container detached, consider whether you can remove the tty allocation, and if you need stdin configured, by removing the -it
:
$ time sudo docker run --cap-add SYS_ADMIN -d \
--memory=100000k --memory-swap=100000k \
-w /tmp -v /home/asd:/tmp my_image
After that, you can start to look at how much time is added to create each of the namespaces for things like the network and pid by disabling them by setting them to the existing host namespace:
$ time sudo docker run --cap-add SYS_ADMIN -itd \
--net=host --pid=host --uts=host \
--memory=100000k --memory-swap=100000k \
-w /tmp -v /home/asd:/tmp my_image
From docker, you can view the actions being performed with docker events
and checking the timestamp on each of the actions.
Lastly, keep in mind that docker is a client/server application, and some of the actual time may be socket/network communication between the client and server.