mrgloom
mrgloom

Reputation: 21602

How to run application from docker container from host OS?

I'm using docker container with ubuntu:14.04 and some C++ application that I compiled inside docker container.

Is it possible to run application that is inside container from host OS(in my case Win 7)?

Something like:

docker run <path-to-binary>/mybinary -f 10 -o output.txt

UPDATE:

Yes, it's possible

docker run -it <my-image> <path-to-binary>/mybinary

So ideally I want application inside docker will be just like native applications on Windows host OS.

Also is it possible to specify files and folder in host OS as input arguments to application that docker container can't see?

UPDATE:

I tried to mount shared folder at container start

docker run -v C:\shared_with_VM:/temp my_image

and also

docker run -v "C:\shared_with_VM":/temp my_image

But I get error:

C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: Invalid
bind mount spec "C:\\shared_with_VM:/temp": invalid mode: /temp.
See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.

As said here right path format on Windows should be

docker run -v /c/shared_with_VM:/temp my_image

Upvotes: 4

Views: 8899

Answers (1)

n2o
n2o

Reputation: 6477

I am not sure if I correctly understand your question...

You can mount folders from your host to the container to make it accessible from within your container:

docker run -v /host/folder:/container/ -it <image> <executable> <arguments>

For example:

docker run -v /tmp:/tmphost -it ubuntu ls -al /tmphost
# or in Windows
docker run -v //c/Users/mrgloom/Desktop/data:/tmphost -it ubuntu ls -al /tmphost

This creates the folder /container/ in your container and links it with /host/folder. You can then bidirectonally read / write files inside these folders. Your binary has to point to the input file, which might be located in /container/input.txt

Upvotes: 4

Related Questions