Container LAMP with Debian Stretch

3

I did some searching on the internet and found no instructions to mount a LAMP container using the official Debian Stretch image ( link ). The idea would be to upload a Docker container with Apache2.4, PHP7.0 and MariaDB 10.3 (for that would be used Docker-compose 3.3 and Dockerfile).

Note: I understand that it would be ideal not to upload everything in a single container, however, if possible, in this specific scenario, I would like to integrate the LAMP structure into a single container, in the worst case the bank could be in a separate container .

Any ideas how to do this?

    
asked by anonymous 24.09.2017 / 02:10

2 answers

1

"Different" from a standalone setup is that you will be running more than one process in your container . Not that containers have been made to run a single process / service, but do everything in one, in addition to "plastering" the container structure and causing it to have several responsibilities ends up taking away some of the advantages they bring, such as ease of service monitoring, process management complexity, image maintainability - even using a provisioner such as puppet or chef -, etc.

>

Anyway, an example of how to make this available would be to use something that would reliably run more than one container process. For this I will use the Honcho , but there are other ways such as Supervisor or even a script that starts every service, commonly seen.

The Honcho option is simplified in the use and management of services, with supervisord the configuration is more extensive and the default constantly generates error in containers . Here's an example using supervisor that even talks about not using too many processes in the same container : link

These would be all the necessary steps for what you need:

  • installation and configuration of Honcho
  • Installing and Configuring Apache2.4
  • installation and configuration of Maria DB 10.3
  • Installing and configuring PHP 7.0

I will not install and configure everything, just part with the Honcho configured and running the Apache and Maria DB services. The rest, with PHP installation and configuration, dynamic settings, and other details you need just do as you need.

Let's start adding the Maria DB repository, plus some utilities for apt . This part will look like this and is self-explanatory:

RUN apt-get update --fix-missing; \
    apt-get upgrade -y; \
    apt-get install -y software-properties-common gnupg; \
    apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8; \
    add-apt-repository 'deb http://mariadb.biz.net.id/repo/10.3/debian stretch main'

This will install Apache, Maria DB and pip , Python package manager, which we will use to install Honcho , in Dockerfile we would have something like this:

RUN { \
        echo "mariadb-server-10.3" mysql-server/root_password password 'unused'; \
        echo "mariadb-server-10.3" mysql-server/root_password_again password 'unused'; \
    } | debconf-set-selections; \
    apt-get install -y apache2 mariadb-common mariadb-server python-pip; \
    sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/my.cnf; \
    rm -rf /var/lib/apt/lists/*

From there differently just the default values of Maria DB's password configuration, so that you do not need to interact with the console when constructing the docker image, we discussed some Maria DB configurations that usually generate errors and finally erase the apt cache, so the image gets smaller.

Finally Honcho , we will need a Procfile file where we specify which commands should be executed to start the services. The content of it will be this:

apache: /usr/sbin/apachectl -DFOREGROUND
mariadb: /usr/bin/mysqld_safe --timezone=UTC

The format is very simple, the first element is the name of the process and the second is the command to run the process.

In Dockerfile to install we will have this:

RUN pip install honcho

And this to compile our Procfile into the image and set the working directory to / , which is where by default the Honcho looks for Procfile :

ADD Procfile /Procfile

WORKDIR /

To start Honcho and it will raise the services of Apache and Maria DB, we will use CMD same, like this:

CMD honcho start

This would be the full version of our Dockerfile :

FROM debian:stretch

ENV DEBIAN_FRONTEND=noninteractive

# adiciona repositório do mariadb
RUN apt-get update --fix-missing; \
    apt-get upgrade -y; \
    apt-get install -y software-properties-common gnupg; \
    apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8; \
    add-apt-repository 'deb http://mariadb.biz.net.id/repo/10.3/debian stretch main'

# instalando apache2, mariadb e python-pip
RUN { \
        echo "mariadb-server-10.3" mysql-server/root_password password 'unused'; \
        echo "mariadb-server-10.3" mysql-server/root_password_again password 'unused'; \
    } | debconf-set-selections; \
    apt-get install -y apache2 mariadb-common mariadb-server python-pip; \
    sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/my.cnf; \
    rm -rf /var/lib/apt/lists/*

# instalando o honcho
RUN pip install honcho

ADD Procfile /Procfile

EXPOSE 80 443 3306

WORKDIR /

CMD honcho start

You can organize the commands as you see fit to generate less layers and have a smaller image.

Our example docker-compose would look like this:

version: '3'
services:
  lamp:
    build:
      context: .
    container_name: sample_multi_process
    image: brunocesar/sample-multi-process:0.0.1-snapshot
    ports:
      - 90:80

In docker-compose you can use whatever you need, such as mapping < in , have a network > specific, deploy , etc.

Verifying that everything is ok with docker-compose ps :

[bruno@bruno docker-multi-process]$ docker-compose ps
        Name                   Command           State                   Ports                
----------------------------------------------------------------------------------------------
sample_multi_process   /bin/sh -c honcho start   Up      3306/tcp, 443/tcp, 0.0.0.0:90->80/tcp

You can view the details with docker-compose logs -f --tail 20 , for example, or access the default Apache page at link - it may be that your is routing correctly, then goes through the docker machine IP.

Finally, there are several examples of LAMP in a single container, such as the linode / lamp and dell / lamp , so you can mount yours as you find most interesting. Also, a search for LAMP in the Docker Hub / Store will return a lot,

    
27.09.2017 / 18:01
0

I see nothing wrong with having an image with all the software needed to run the system. This is normal for anyone who uses Docker for integration testing.

I do not have much experience with Docker, consider what I'm going to say as a suggestion:

Find a Dockerfile that does what you want. At the moment, link looks like a good candidate. As it is based on Ubuntu, I would just change:

FROM ubuntu:16.04

for

FROM debian:stretch

You can fork the repository: link

    
27.09.2017 / 02:46