dockerbinarycontainersmountssmtp

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 .


Solution

  • 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)