Interface between applications running inside and outside a docker container

I am running Ubuntu 20.04 and am using the Nvidia Riva Automatic Speech Recognition application to detect speech commands. I would like to direct/pipe them into another application to execute a control action. The problem I have is that the ASR application is deployed within a docker container and the control application is not.

Therefore. I would like to know how an application running outside the docker container may interface with an application running inside.

I have considered running everything inside the same container, however this is not practical because our product is mature, has lots of services interacting with each other, and also interfaces to linux kernel drivers.

Thanks in advance for any help.

Asked By: user5265160

||

There are two very obvious interfaces between a Docker Container and the host that you should probably explore further:

  1. Published ports
  2. Bind mounts (persistent storage)
Published ports

One option when running a container is to map ports from the container to the host. This can be used for web interfaces etc., but also to exchange other data via TCP or UDP port mapping.

To map a port between container and host, use the -p option with this syntax following syntax:

docker run -p <host-port>:<container-port> <IMAGE>

Example: You want to map TCP port 80 in the container to port 8080 on the host (the /tcp is optional, since its the default).

docker run -p 8080:80/tcp <IMAGE>
Bind mounts

Another option is so use bind mounts to map files between the host filesystem and the container. These files are mapped in realtime, so any updates happening in the container should be immediately reflected in the filesystem.

To map files between container and host, use the -v option with this syntax following syntax:

docker run -v /path/on/host:/path/in/container <IMAGE>

Example: You want to map the path /data in the container to the path home/user/data on the host.

docker run -v /home/user/data:/data <IMAGE>

Note that additional mappings can also be done for single files:

docker run -v /home/user/data:/data -v /usr/local/etc/container.conf:/etc/container.conf <IMAGE>
Answered By: Artur Meinild
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.