Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transition Virtual Hosts to Docker Containers

I currently run a Red Hat Linux server with Plesk to host a hundred or so domains. For multiple reasons I'd like to transition away from Plesk and to Docker containers with each virtual host as one or more containers. I'm unclear from what I've read so far what would be the best approach to this.

A typical site includes the doc root file area and one or two MySQL databases. We run PHP on all the sites. Some sites may have constraints on the version of PHP they can run. Some of the sites use SSL. I don't believe there are any constraints on the MySQL versions, but it's of course possible that future MySQL versions could deprecate some feature that is needed. I don't believe there's any dependency on the Apache version, but I do rely on some specific Apache modules being installed. There may be a site or two that have dependencies outside of their doc root and not part of the basic virtual host setup, but I don't believe any require a specific version of Linux.

I would like the containers to have maximum portability so that I can have flexibility in moving sites to whatever server or cloud service I choose. Part of my goal is to retire the current server and move sites to servers which best fit them.

I would also like to try upgrading the PHP version after the containers are created.

So would a single container include the entire doc root file system, including the data directories where users can upload/ftp files? Would it include the MySQL database, or would that be separate? I assume I would include the current version of PHP so that I could upgrade each one when I was ready. Would it include Apache when specific Apache modules are required? Is there a reason to include Apache and/or MySQL in all containers?

One last piece. I'm looking into using CoreOS which utilizes Docker as an integral part.

Any and all inputs are appreciated.

like image 414
Darryl Avatar asked Aug 04 '14 17:08

Darryl


People also ask

Can you run a VM in a Docker container?

To run a Docker container, you: create a new (or start an existing) Docker virtual machine. switch your environment to your new VM. use the docker client to create, load, and manage containers.

Can Docker replace VM?

Not a Complete Replacement The point of view among some experts is that although containerization offers many benefits, it will not completely replace virtual machines. That's because containerization and virtual machines have particular capabilities that help solve different solutions.


1 Answers

The whole idea of Docker is running processes/components isolated, to keep them easily upgradable. I have tinkered with this in the past and have come up with the following.

  • Create four containers per instance (customer):
    • Apache or nginx
    • php-fpm
    • MySQL
    • Busybox (as a data container)
  • Link all of them together and set volumes to all data that should persist in the data container. MySQL data and /var/www plus site config files for example.

This way you can always switch out one of the components while keeping the others. It's questionable though if Docker is a solution to a full virtual server though, as Docker containers do not have a full init system and you'll have to resort to bending things quite a bit to resemble a full virtual machine. Think more of it as "application containers", hence the idea with the separation of concerns.

Update:

Newer Docker versions come with the docker-compose tool which greatly eases this task.

like image 94
herrbischoff Avatar answered Oct 11 '22 12:10

herrbischoff