简体   繁体   English

从docker容器中的主机运行可执行文件

[英]Run executable from host within docker container

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. 我有一个docker容器,我想在主机操作系统中启动一个进程,然后让它在docker容器的上下文中执行。 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 eg 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! 我确实意识到尝试使用docker容器这有点奇怪!

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. 唯一的问题是你还需要注意确保容器中还有任何所需的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM