Run Magento into docker

Since some weeks, my e-commerce store is running under Docker !

In fact, an upgrade of my linux distribution had broken my Magento installation and I have decided to migrate it into a docker container : It is more secure and an host upgrade will not impact the container and version installed.

It is working as expected without issues and you will increase the security of your website as it will run into a isolated container.

I am using the following Dockerfile :

FROM ubuntu:14.04
MAINTAINER Nicolas Portais
ENV HOST=docker4.local
ENV DOMAIN=local
ENV RELAY="your_smtp_server"
ENV ORIGIN="your_domain"
ENV PHP_FPM_USER=www-data
RUN apt-get update && apt-get install -y mariadb-server-5.5 mariadb-client-5.5 php5-fpm php5-imap php5-mysql php5-cli php5-imap php5-curl libcurl3 libcurl3-gnutls php5-cli php5-gd php5-imagick php5-mcrypt php5-readline openssh-client telnet supervisor php5-curl php5-fpm php5-cli memcached php5-memcache php5-memcached postfix mailutils rsyslog libsasl2-modules patch dnsutils && apt-get clean
RUN touch /var/log/php5-fpm.log
RUN chown  www-data /var/log/php5-fpm.log
RUN touch /var/run/php5-fpm.pid
RUN chown www-data /var/run/php5-fpm.pid
RUN update-rc.d -f memcached remove
RUN rm /etc/php5/fpm/pool.d/www.conf
RUN rm /etc/php5/fpm/php.ini
RUN rm /etc/php5/cli/php.ini
COPY php5_cli_php.ini /etc/php5/cli/
RUN mv /etc/php5/cli/php5_cli_php.ini /etc/php5/cli/php.ini
COPY php5_fpm_php.ini /etc/php5/fpm/
RUN mv /etc/php5/fpm/php5_fpm_php.ini /etc/php5/fpm/php.ini
COPY www.conf /etc/php5/fpm/pool.d/
#COPY s_mysqld.conf /etc/supervisor/conf.d/
COPY s_php5-fpm.conf /etc/supervisor/conf.d/
COPY s_memcached.conf /etc/supervisor/conf.d/
COPY s_cron.conf /etc/supervisor/conf.d/
COPY s_postfix.conf /etc/supervisor/conf.d/
COPY s_rsyslogd.conf /etc/supervisor/conf.d/
COPY docker_service.sh /
RUN chmod 755 /docker_service.sh
RUN cd /usr/local && tar -xzvf /ioncube_loaders_lin_x86-64.tar.gz
COPY www-data /var/spool/cron/crontabs/
RUN chown www-data:crontab /var/spool/cron/crontabs/www-data
RUN /usr/sbin/postconf -e myhostname=$HOST 
RUN /usr/sbin/postconf -e mydomain=$DOMAIN 
RUN /usr/sbin/postconf -e mydestination=''
RUN /usr/sbin/postconf -e mynetworks='127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128' 
RUN /usr/sbin/postconf -e inet_interfaces=loopback-only 
RUN /usr/sbin/postconf -e relayhost=$RELAY
RUN /usr/sbin/postconf -e myorigin=$ORIGIN
RUN /usr/sbin/postconf -e smtp_sasl_auth_enable=yes
RUN /usr/sbin/postconf -e smtp_sasl_password_maps=hash:/etc/postfix/sasl-passwords
RUN /usr/sbin/postconf -e smtp_sasl_mechanism_filter=digest-md5
RUN /usr/sbin/postconf -e smtp_sasl_security_options=''
RUN cp /etc/services /var/spool/postfix/etc/
RUN cp /etc/resolv.conf /var/spool/postfix/etc/
COPY sasl-passwords /etc/postfix/
RUN /usr/sbin/postmap hash:/etc/postfix/sasl-passwords
EXPOSE 9000
ADD ./my.cnf /etc/mysql/

Notes:

  • I am using supervisord to start all the processes and you must create/use your own configuration files.
  • My database is running into an another container but you can run your database  under the host or into the same container.

Build the container using the following script:

#/bin/sh
DATE=$(date +%Y%m%d)
docker build -f Dockerfile -t ubuntu/magento-${DATE} .

Note that I add the date to manage the versioning.

$ ./build-DATE.sh

I start the container with the following script :

#/bin/sh
DATE=$(date +%Y%m%d)
docker run -d -it -v /www/magento_docker:/www/magento_docker \
	       -p 127.0.0.1:9001:9000 \
	--name magento-prod-${DATE} \
	--restart=always \
	--hostname docker4 \
	ubuntu/magento-${DATE} /docker_service.sh

and run the command:

$ ./start_magento-DATE.sh

There are a lot of tests before getting a working environment : you should take attention to postfix and verify that the container can send emails.

I had migrated a working Magento environment from the host to the docker container.

So It is better to have already a working Magento environment and there are some days of work to get a working environment.

I will give more detail to those who will donate.

Nicolas Portais
Author Photographer
http://www.mystockphoto.fr/
http://photos-art.pro/

Ce contenu a été publié dans Anglais, Magento, avec comme mot(s)-clé(s) , , , , , , , , . Vous pouvez le mettre en favoris avec ce permalien.

1 Response to Run Magento into docker

  1. devops online training dit :

    Nice Article. In short description good explanation about the DevOps. Thanks For sharing the informative news.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Captcha (solve the arithmetic equation) * Time limit is exhausted. Please reload CAPTCHA.