Reputation: 10781
Is there a way to eliminate the overhead of docker exec? For example, when I call docker exec ls
on an already-running container, it takes 0.15s to return the result.
root@min:/# time docker exec 6f ls
bin
boot
dev
etc
home
lib
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
real 0m0.159s
user 0m0.028s
sys 0m0.028s
However if I start the container attached, and ls
from the container's command line, it only takes a couple ms.
root@min:/# docker start -ai 6f
[root@6f384443d3a6 /]# time ls
bin boot dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
real 0m0.004s
user 0m0.003s
sys 0m0.000s
The containers were created as follows:
$ docker create -t -i fedora bash
6f8af538ec541dd581ebc2a24153a28329acb5268abe5ef868c1f1a261221752
$ docker start 6f
What is the overhead in docker exec
, and is there a way to reduce it? (I'm trying to make a service that hosts running containers and calls executables on them and returns the results. But if it's going to take 150ms per call, then that's no good).
Upvotes: 2
Views: 1879
Reputation: 160000
Docker is implemented as an HTTP-based service, which is usually called over a Unix socket. For example, you can see the "create an exec instance" request in the Docker API documentation. It takes at least two round-trips to run a docker exec
command, plus the overhead of starting the host-side docker
process. On native Linux the HTTP calls will be over a Unix socket; on other platforms, depending on your setup, it may need to cross a VM boundary or even go over TCP.
150 ms for a single docker exec
call intuitively feels a little slow to me, but not out of the realm of the reasonable. There's not much you can do to speed it up, since all of these mechanics are inside the docker
client tool and server daemon.
A typical Docker setup will have containers running long-running server processes (not a bare fedora
container, and not a bash
shell as the main container process). You should be able to make a network request to the container, and this will likely be faster than docker exec
(and not require administrator privileges).
Upvotes: 5