4

I have built docker container system where container contains a command line application. I pass arguments and run the application using docker exec command from another application.

When I run the command line application from inside docker, it takes 0.003s to run.

$ time comlineapp "hello"

But when I run it from outside docker using docker exec, it takes 0.500s

$ time docker exec comline app "hello"

So clearly docker exec takes lot of time. We need any help to reduce the time as much as possible for docker exec command.

Here is the docker file

FROM ubuntu:18.04

RUN adduser --disabled-password --gecos "" newuser

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get -y install time && \
    apt-get -y install gcc mono-mcs && \
    apt-get install pmccabe && \
    rm -rf /var/lib/apt/lists/*

all required softwares are already installed.

user1235483
  • 111
  • 1
  • 1
  • 5
  • Can you please share your dockerfile? Do you install software when the container is started or do any other operations at container-startup before starting the app? – Turing85 Aug 15 '20 at 20:43
  • I have ypdated question with the docker file details. All required softwares are already installed. The application I was talking is gcc which I call from outside. – user1235483 Aug 16 '20 at 06:13
  • 1
    Have similar concern, however I am getting only 170ms overhead. I do not have any idea yet, but I run strace ( `strace -ttt -T -f docker exec ...`), and it yields interesting hints. Additionally I've learned that `docker` CLI is actually using HTTP protocol to access docker engine, so this may also be the reason of the overhead. – Kuchara Nov 13 '20 at 17:08
  • @Kuchara did you get any further on this? – Dax Fohl Nov 18 '20 at 14:13
  • This is answered here https://stackoverflow.com/questions/64894654/is-there-a-way-to-speed-up-docker-exec/64895568#64895568 – Dax Fohl Nov 18 '20 at 15:10

2 Answers2

2

When you send a request from outside docker, there’s (multiple) API requests over a unix socket and lots of extra setup for the process itself such as applying a seccomp profile, setting namespaces, dropping privileges, etc. The proper way to leverage docker is to create a service inside it and then have the endpoints take care of these. A simple python service should cater to this. We changed the same in our platform and saved 1000s of ms post that.

Mintu Paul
  • 31
  • 2
0

In my case, I discovered a problem running journalctl -u docker.service | tail -n 50 which threw the following error:

level=error msg="failed to get longest-active member" error="failed to find longest active peer"

It was fixed by leaving the Docker swarm with the command docker swarm leave and starting it again with docker swarm init

Genarito
  • 3,027
  • 5
  • 27
  • 53