Instalar lamp en docker con tutum/lamp


tutum-docker-lamp

Out-of-the-box LAMP image (PHP+MySQL)

Usage

To create the image tutum/lamp, execute the following command on the tutum-docker-lamp folder:

docker build -t tutum/lamp .

You can now push your new image to the registry:

docker push tutum/lamp

Running your LAMP docker image

Start your image binding the external ports 80 and 3306 in all interfaces to your container:

docker run -d -p 80:80 -p 3306:3306 tutum/lamp

Test your deployment:

curl http://localhost/
Hello world!

 

Loading your custom PHP application

In order to replace the “Hello World” application that comes bundled with this docker image, create a new Dockerfile in an empty folder with the following contents:

FROM tutum/lamp:latest
RUN rm -fr /app && git clone https://github.com/username/customapp.git /app
EXPOSE 80 3306
CMD ["/run.sh"]
replacing https://github.com/username/customapp.git with your application's GIT repository. After that, build the new Dockerfile:
docker build -t username/my-lamp-app .

And test it:

docker run -d -p 80:80 -p 3306:3306 username/my-lamp-app

Test your deployment:
curl http://localhost/
That's it!

Connecting to the bundled MySQL server from within the container

The bundled MySQL server has a root user with no password for local connections. Simply connect from your PHP code with this user:

<?php
$mysql = new mysqli("localhost", "root");
echo "MySQL Server info: ".$mysql->host_info;
?>

Connecting to the bundled MySQL server from outside the container

The first time that you run your container, a new user admin with all privileges will be created in MySQL with a random password. To get the password, check the logs of the container by running:

docker logs $CONTAINER_ID

You will see an output like the following:
========================================================================
You can now connect to this MySQL Server using:

    mysql -uadmin -p47nnf4FweaKu -h<host> -P<port>

Please remember to change the above password as soon as possible!
MySQL user 'root' has no password but only allows local connections
========================================================================
In this case, 47nnf4FweaKu is the password allocated to the admin user.
You can then connect to MySQL:

mysql -uadmin -p47nnf4FweaKu

Remember that the root user does not allow connections from outside the container - you should use this admin user instead!

Setting a specific password for the MySQL server admin account

If you want to use a preset password instead of a random generated one, you can set the environment variable MYSQL_PASS to your specific password when running the container:

docker run -d -p 80:80 -p 3306:3306 -e MYSQL_PASS="mypass" tutum/lamp

You can now test your new admin password:

mysql -uadmin -p"mypass"

Disabling .htaccess

.htacess is enabled by default. To disable .htacess, you can remove the following contents from Dockerfile
# config to enable .htaccess
ADD apache_default /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite
by http://www.tutum.co

El Dockerfile es:

FROM ubuntu:trusty
MAINTAINER Fernando Mayo <fernando@tutum.co>, Feng Honglin <hfeng@tutum.co>

# Install packages
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
  apt-get -y install supervisor git apache2 libapache2-mod-php5 mysql-server php5-mysql pwgen php-apc php5-mcrypt

# Add image configuration and scripts
ADD start-apache2.sh /start-apache2.sh
ADD start-mysqld.sh /start-mysqld.sh
ADD run.sh /run.sh
RUN chmod 755 /*.sh
ADD my.cnf /etc/mysql/conf.d/my.cnf
ADD supervisord-apache2.conf /etc/supervisor/conf.d/supervisord-apache2.conf
ADD supervisord-mysqld.conf /etc/supervisor/conf.d/supervisord-mysqld.conf

# Remove pre-installed database
RUN rm -rf /var/lib/mysql/*

# Add MySQL utils
ADD create_mysql_admin_user.sh /create_mysql_admin_user.sh
RUN chmod 755 /*.sh

# config to enable .htaccess
ADD apache_default /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite

# Configure /app folder with sample app
RUN git clone https://github.com/fermayo/hello-world-lamp.git /app
RUN mkdir -p /app && rm -fr /var/www/html && ln -s /app /var/www/html

#Enviornment variables to configure php
ENV PHP_UPLOAD_MAX_FILESIZE 10M
ENV PHP_POST_MAX_SIZE 10M

# Add volumes for MySQL 
VOLUME  ["/etc/mysql", "/var/lib/mysql" ]

EXPOSE 80 3306
CMD ["/run.sh"]

CREAR UN DIRECTORIO COMPARTIDO CON EL HOST:

docker run -i -t -p 80:80 -v  /home/jose/paginas:/var/www/html/  tutum/lamp:latest /bin/bash

Con esto podremos agregar,  modificar  o borrar  las paginas web del  container desde  nuestro host, sin necesidad de entrar en el docker-container.

Comentarios