Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any solution to execute binary in container that mount from host?

In my case , I have installed ssmtp package on my Unix based host . Because of some reason , the best way in my situation is using ssmtp binary(under /usr/sbin) on my host to send mail (html file) in my APP container .

I attemp to mount the host directory /usr/bin into container:

docker run -v /usr/sbin:/host_sbin --name=myapp -ti -p 889:80 -p 890:5432 myimage

and try to execute ssmtp , here are some awkward tries and their results :

In my APP container and under /host_sbin

 ssmtp   --->  bash: ssmtp: command not found
./ssmtp  --->  bash: ./ssmtp: No such file or directory

So it seems that things are not simple as I think . Could anyone have done something like this share the solution with me ? And I'd appreciate if someone can explain me why that not work .

like image 286
Carr Avatar asked Dec 28 '15 15:12

Carr


People also ask

Can docker containers communicate with the host?

If you are running more than one container, you can let your containers communicate with each other by attaching them to the same network. Docker creates virtual networks which let your containers talk to each other. In a network, a container has an IP address, and optionally a hostname.

How do I mount a host volume to a docker container?

To mount a data volume to a container add the --mount flag to the docker run command. It adds the volume to the specified container, where it stores the data produced inside the virtual environment. Replace [path_in_container] with the path where you want to place the data volume in the container.


1 Answers

Simply mounting the binary into your container does not work as the ssmtp binary is probably not statically linked. Instead it is linked dynamically to a set of shared libraries that are present in your host system, but not in your container. You can verify this using the ldd command, whilch will print all libraries that the ssmtp binary is linked against:

> ldd /usr/sbin/ssmtp

If you wanted to use your host ssmtp binary, you would also have to mount all required shared libraries into your container (and adjust the library path and so on; I'd recommend not to).


Here's my suggestion: The important bit is probably not the ssmtp binary, but SSMTP's configuration files (depending on your distribution, but typically found in /etc/ssmtp). I'd suggest...

  1. Installing ssmtp inside your container using the image's native package manager. Do not mount the binary from the host into the container.
  2. Mount the hosts SSMTP configuration files into your container (using the -v /etc/ssmtp:/etc/ssmtp flag on container creation)
like image 192
helmbert Avatar answered Sep 21 '22 11:09

helmbert