1

Topic: Building a Docker image

==== Required information ====
- iRedMail version:
- Store mail accounts in which backend (LDAP/MySQL/PGSQL):
- Web server (Apache or Nginx):
- Linux/BSD distribution name and version:
- Related log if you're reporting an issue:
======== Required information ====
- iRedMail version: 0.9.0
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Nginx
- Linux/BSD distribution name and version: Ubuntu 14.04
- Related log if you're reporting an issue:
====

I am writing some scripts to build a Docker image for iRedMail: https://github.com/docker-build/iRedMail
I would like to make an initial installation inside this image, so that the necessary packages
are already installed. I have tried to do this by using a dummy 'config' file and a command
like this: `echo y | ./iRedMail.sh` (see: https://github.com/docker-build/iRedMai … le#L17-20)
However it is not possible to set a FQDN during the process of building an image,
so the installation script refuses to continue.

Is it possible to circumvent it somehow, or at list to download and install all the necessary
packages, without doing all the configurations?

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Building a Docker image

dashohoxha wrote:

However it is not possible to set a FQDN during the process of building an image

You can hack the iRedMail scripts to show a dialog and ask admin to enter the FQDN.

By the way, i guess this tutorial will help a little:

- Perform silent/unattended iRedMail installation
  http://www.iredmail.org/docs/unattended … ation.html

3

Re: Building a Docker image

By the way, you may want to generate random passwords used in 'config' file, so that your docker users won't use same passwords.

4

Re: Building a Docker image

First of all, thanks for your reply (and for iRedMail of course, it is a great tool).

I have seen the doc about the silent/unattended installation. With the 'config' file in place and with the command `echo y | ./iRedMail.sh` it works, it will find the config file, will pick it up, and will continue installation without asking questions. Why `echo y`? Because it still needs a confirmation in order to use the config file. Why silent installation? Because this is just an initial configuration which will later be overriden by the users, so any configuration details at this point make no sense, they just stop the automatic building of the image.

Let me explain that this unattended installation is just an initial installation, so that all the needed packages can be installed. After users create a container, they are going to repeat the installation again, in order to set the proper FQDN, proper passwords, etc. So, it doesn't make sense to generate random passwords at this stage, or to ask admin for the FQDN.

I am not sure whether I am explaining it clearly enough.

5

Re: Building a Docker image

I just updated README: https://github.com/docker-build/iRedMai … /README.md
Maybe these instructions can help you to understand the process that I am thinking.
I want to do most of the installations during the build phase (when the docker image is built)
and later customize the configuration as needed.

6

Re: Building a Docker image

OK, i understand this is just a testing phase.

dashohoxha wrote:

Why `echo y`? Because it still needs a confirmation in order to use the config file.

As mentioned in the tutorial, you can use 'AUTO_USE_EXISTING_CONFIG_FILE=y' instead:

# AUTO_USE_EXISTING_CONFIG_FILE=y bash iRedMail.sh

7

Re: Building a Docker image

ZhangHuangbin wrote:

As mentioned in the tutorial, you can use 'AUTO_USE_EXISTING_CONFIG_FILE=y' instead:

OK, I had missed this.

8

Re: Building a Docker image

I've built a docker container with a prebuilt config (external config generator).
The images downloads iredmail tar and your prebuilt config.

Then you can define hostname (-h) and ports (-p) when creating the container.
There's then a script to verify if iredmail is installed in the container or not (else start services).

But I agree and image with pre-downloaded pkgs and only installation would smoother.

9 (edited by bmackay 2015-08-19 10:03:46)

Re: Building a Docker image

I'm a bit curious as to what the thinking is behind creating a docker container with iRedAPD, postfix, dovecot, mysql, openldap and apache all stuffed into one container.  It seems to me that this is taking the architecture of a dedicated server or VM and trying to transplant it more or less intact into Docker.

Docker is really about deploying fault tolerant applications that consist of microservices distributed across multiple docker hosts.  The idea being that you can scale individual services, set anti-affinity policies on specific containers, define which containers are allowed to communicate, etc...   Moving a complex application to container space really means rethinking the architecture.

So unless you're deploying microservices that scale (ie clustering) I don't understand what you're trying to do.  Perhaps this isn't a production system and just someone's dev box?

iRedMail's installer by design is somewhat counter to the Docker philosophy.   iRedMail is somewhat of a "super package" which helps you install and manage the many packages which are needed to run a complex mail server.   I think what's needed for iRedMail to run in a Docker environment in any meaningful way is to have a separate installer specifically for containerization and clustered versions of the core components which would reasonably be broken out into separate containers.  At first blush, the logical components to break out into separate pods (microservices) might be:  iRedAPD+Postfix, Dovecot, Amavis+SpamAssassin, Apache+RoundCube, OpenLDAP, MySQL.

Because of the complexity of the interaction between these components  (if it wasn't complex, we wouldn't need iRedMail in the first place), I would suggest that the iRedMail installer be used in conjunction with an orchestration tool like Kubernetes.   This would offload a lot of the funky scripting that you've been discussing and ensure the correct number of each pod is running by monitoring it through the replication controller.   It would also offload a bucket load of other tasks that get fairly complex in the Docker world when you start gluing together numerous containers that need to intercommunicate securely and scale.

I'd be very happy to contribute to work on a project of this nature if I could be of any assistance, but I believe the task is fairly large and probably only of interest to a small number of iRedMail admins.

10

Re: Building a Docker image

What you say is true, but using Docker has some benefits other than those that you mention. I use Docker as a VM for my production servers and everything is fine. Docker can be as much complicated as you explain, but it doesn't have to be, it can also be as simple as a VM.

Anyway, if you prefer complex configurations, you can start simple (putting all the services in one container), and then start to factor them out one by one (MySQL, OpenLDAP, etc.) If you would like to work on such a project, I would suggest that you start with my scripts, and then improve them gradually, while always checking that they work. I have stopped using iRedMail, so I cannot help you on this task.

11 (edited by bmackay 2015-08-19 17:38:11)

Re: Building a Docker image

I suppose this begs the question of what your goals were for trying to run a mail server from a single container.

VMs and containers are fundamentally different beasts with very different approaches to application deployment.  If you want everything running from a single container, what you really want is a VM.   There are lots of virtualization platforms out there without subverting Docker to try to make it act like a VM.

By definition, Docker is "a platform for distributed applications".  Two of the fundamental principles of Docker are that containers should be ephemeral and that a container should only run one process.  Your approach ignores both of these best practice design recommendations, so it's not really suitable as a starting point for a properly containerized mail server deployment.  It might be useful if someone wants to build a Vagrant image though.

So this isn't a matter of preferring complex configurations, simply whether Docker is appropriate as your weapon of choice for deploying your application.    If you're not building a scalable, fault tolerant mail server, Docker is the wrong tool.  If you're not planning to deploy to multiple Docker hosts, you're probably wasting your time breaking iRedMail up into distributed components.   After all, the point of distributed apps is building horizontal scalability.

Everyone is jumping on the Docker bandwagon and you'll find both GitHub and DockerHub littered with bad examples of monolithic apps simply stuffed into a container as if it were a VM appliance.

I suppose the idea of a distributed application and the principle of one process per container is fairly straight forward.   What seems to be less understood is the idea of "ephemeral containers".   This is fundamentally contrary to what we've done traditionally with physical servers and VMs.   Docker evangelists describe this using Bill Baker's analogy of pets versus cattle.  VMs and physical servers were pets which we named and nursed back to health when they were sick.   Containers are cattle which you number and shoot if they get sick.   In other words, you can use a replication manager to spin up multiple horizontal scaling instances of what Kubernetes calls a "pod".   If one dies, you check the number of running instances and fire up another or kill one off if you manage to have more running than what you specified.

So yes, deploying all of the elements of iRedMail as "cattle" would be a big and relatively complicated job, but that's what Docker is intended for.   Once the work was done, this could perhaps open up iRedMail to Enterprise class customers, but arguably that space is completely occupied by MS Exchange and commercial IMAP providers like Google, MS Outlook Live, etc...

12

Re: Building a Docker image

Docker is not the wrong tool, as long as it does the job right, despite your definitions and categorizations.

I will show you a counterexample that brings down all your theoretical reasoning: https://github.com/discourse/discourse_docker

After testing and getting familiar with it, you will understand that docker is more flexible and powerful than what you think, and it can be a perfect solution for a wider range of situations than what you think. Can it be a good solution for iRedMail? I think yes. But actually I don't care.