0

Im currently working on a Web interface for my personal mailserver and This requires me to work with two different containers: A PHP Container and a Mailserver container. Now Im using Docker-Mailserver (https://hub.docker.com/r/mailserver/docker-mailserver/) and Id like to be able to make Accounts and their Mailboxes within my Webinterface instead of using a bash script as it currently is. From what I understand this requires me to launch a script located within the Mailserver Container at /usr/local/bin thats named setup The problem now is How do I share /usr/local/bin with my PHP Container? The folder already exists so I cant just make a Volume (to my knowledge) and Im now stuck at a standstill. Oh and I do NOT have access to the directory that needs to be shared from host. It is one I can only find in the docker container.

As it stands Ive tried looking around the internet however so far Ive been unable to find anything very useful. Theres alot of articles about Volumes however these create a new folder and from what I know do not work with existing folders. Networking could work however I doubt it since it is a script that needs to be executed instead of just a regular file.

Mayflower
  • 1
  • 2
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Dec 06 '22 at 13:17

1 Answers1

0

You can use a shared volume. With docker, you can rely on the fact that new empty named volumes are populated with the content of the container its mounted to. See https://docs.docker.com/storage/volumes/#populate-a-volume-using-a-container.

You can run the executable from any path, it could be /user/local/bin/ or any other path that is set inside the $PATH variable to have it automatically discovered without the full path, but you can also just use the full path to some arbitrary location.

To get the general idea, look at the below example. note that the order is important. Since the first run command creates the volume and populates it while the second run command mounts the already populates volume.

docker run -d \
  --name=mailserver \
  -v mailbin:/usr/local/bin \
  mailserver-image

docker run \
  --name=php \
  -v mailbin:/tmp/mailserver/bin \
  php-app /tmp/mailserver/bin/some-executbale

This is specific to docker. If you want to do something like this in, say, Kubernetes, you would need to use an entrypoint in your mail server to copy the binary you want to share to a shared volume.

The Fool
  • 16,715
  • 5
  • 52
  • 86
  • You might run into problems with missing shared libraries doing this, since the binaries in one image might rely on libraries that aren't found in the other. – Hans Kilian Dec 06 '22 at 13:23
  • @HansKilian, yes, this also came to my mind. Let's cross the fingers and hope for the best, I guess. I think in many cases it would work out, though. Maybe there is also a static version of the mail thing that would be more solid. – The Fool Dec 06 '22 at 13:28
  • im following this now and Im wondering how to do this in a docker-compose.yml I thought itd just be `volumes - named_volume:/usr/mail/bin` however this results in it complaining about an undefined volume – Mayflower Dec 06 '22 at 13:34
  • @Mayflower, You can try to use the volumes key, but I think it will be different in that the volume is created first and not populated with the container's content. Thats why my last paragraph is relevant. In many cases using an entrypoint is more solid and probably preferred. You could populate the volume in the entrypoint yourself. Otherwise you could use some tricks with bind mounts, see https://stackoverflow.com/questions/70892692/docker-compose-up-not-mounting-volumes-in-the-host-directory/70892798#70892798 – The Fool Dec 06 '22 at 13:42
  • Hmmm Alright thank you. Im still new to docker so Entrypoints dont ring a bell for me just yet but Ill google around and see if they can solve my issue. A little disappointing that docker-compose cant populate it but Ill take what I can get. One more thing from me: I am not quite sure what the trick with the bind mounts are in the linked post? If youre fine with it could you tell me a little bit more about that? – Mayflower Dec 06 '22 at 13:50