user1235483
user1235483

Reputation: 121

Docker exec command is very slow

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.

Upvotes: 5

Views: 3573

Answers (2)

Genarito
Genarito

Reputation: 3433

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

Upvotes: 0

Mintu Paul
Mintu Paul

Reputation: 41

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.

Upvotes: 2

Related Questions