Is there any solution for executing a binary in a container that is mounted from the host?

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

I am trying to set the host directory / usr / bin to a container:

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

and try ssmtp, here are some uncomfortable attempts and their results:

In the APP container and in / host_sbin

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

So, it seems that everything is not as simple as I think. Can anyone do something like this to share with me? And I would appreciate it if someone could explain to me why this is not working.

+5
source share
1 answer

Simply creating a binary in your container does not work, as the ssmtp binary is probably not statically linked. Instead, it is dynamically linked to a set of shared libraries that are present on your host system, but not in your container. You can verify this with the ldd command, while it will print all the libraries to which the ssmtp binary is bound:

 > ldd /usr/sbin/ssmtp 

If you want to use your ssmtp host, you will also need to install all the necessary shared libraries in your container (and adjust the library path, etc., I would recommend not to do this).


Here's my suggestion: the important bit is probably not ssmtp binary, but the SSMTP configuration files (depending on your distribution, but usually located in /etc/ssmtp ). I would recommend...

  • Install ssmtp inside your container using the built-in image package manager. Do not mount the binary from the host to the container.
  • Install the SSMTP host configuration files in your container (using the -v /etc/ssmtp:/etc/ssmtp flag when creating the container)
+6
source

Source: https://habr.com/ru/post/1239356/


All Articles