Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run executable from host within docker container

Tags:

docker

I have a docker container and I would like to start a process in the host OS, and then have it execute in the context of the docker container. That is, my executable is a file in the host filesystem, and I want to start a process in the host OS, but I want to contain that process to the container, so that e.g. the process can only access the container's filesystem, etc.

For various reasons I do not want to copy the executable into the container and execute it there.

I do realize that this is a somewhat strange thing to be trying to do with docker containers!

like image 457
Alex Flint Avatar asked May 21 '15 00:05

Alex Flint


People also ask

Can a docker container run commands on host?

Yes. But it's sometimes necessary. @KCD And why they prefer app-containerization via docker instead of using system-level containers (LXC)?

Can I run any application in a container?

You can run any application in Docker as long as it can be installed and executed unattended, and the base operating system supports the app. Windows Server Core runs in Docker which means you can run pretty much any server or console application in Docker.

Can docker containers access files on host?

Docker provides two ways for containers to save files on the host system so that the files are persistent even after the container is shut down. These are Docker volumes and bind mounts. This blog will teach you how to share data between a Docker containerized application and the host computer.


1 Answers

Mount the executable into the container with a volume like this:

$ docker run -v /path/to/executable:/my_exe debian /my_exe

The only problem is you will also need to take care of making sure any required libraries are also available in the container.

like image 175
Adrian Mouat Avatar answered Sep 24 '22 05:09

Adrian Mouat