├── .editorconfig ├── .env ├── .gitignore ├── LICENSE ├── README.md ├── docker-compose.yml ├── docker ├── mysql │ └── Dockerfile └── php │ └── Dockerfile └── www └── info.php /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 2 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.php] 12 | indent_size = 4 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | # Project Options 2 | PROJECT_NAME=docker 3 | 4 | # PHP Options 5 | PHP_VERSION=7.4-apache 6 | PHP_PORT=80 7 | 8 | # MySQL Options 9 | MYSQL_VERSION=5.7 10 | MYSQL_USER=dbuser 11 | MYSQL_PASSWORD=dbpass 12 | MYSQL_DATABASE=dbname 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Hidden files 2 | *.DS_Store 3 | *Thumbs.db 4 | 5 | # editor files 6 | .idea* 7 | 8 | # composer vendor files 9 | vendor/ 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 KODETOP 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker: PHP & MySQL 2 | 3 | Instala rápidamente un ambiente de desarrollo local para trabajar con [PHP](https://www.php.net/) y [MySQL](https://www.mysql.com/) utilizando [Docker](https://www.docker.com). 4 | 5 | Utilizar *Docker* es sencillo, pero existen tantas imágenes, versiones y formas para crear los contenedores que hacen tediosa esta tarea. Este proyecto ofrece una instalación rápida, con versiones estandar y con la mínima cantidad de modificaciones a las imágenes de Docker. 6 | 7 | Viene configurado con `PHP 7.4` y `MySQL 5.7`, además se incluyen las extensiones `gd`, `zip` y `mysql`. 8 | 9 | ## Requerimientos 10 | 11 | * [Docker Desktop](https://www.docker.com/products/docker-desktop) 12 | 13 | ## Configurar el ambiente de desarrollo 14 | 15 | Puedes utilizar la configuración por defecto, pero en ocasiones es recomendable modificar la configuración para que sea igual al servidor de producción. La configuración se ubica en el archivo `.env` con las siguientes opciones: 16 | 17 | * `PHP_VERSION` versión de PHP ([Versiones disponibles de PHP](https://github.com/docker-library/docs/blob/master/php/README.md#supported-tags-and-respective-dockerfile-links)). 18 | * `PHP_PORT` puerto para servidor web. 19 | * `MYSQL_VERSION` versión de MySQL([Versiones disponibles de MySQL](https://hub.docker.com/_/mysql)). 20 | * `MYSQL_USER` nombre de usuario para conectarse a MySQL. 21 | * `MYSQL_PASSWORD` clave de acceso para conectarse a MySQL. 22 | * `MYSQL_DATABASE` nombre de la base de datos que se crea por defecto. 23 | 24 | ## Instalar el ambiente de desarrollo 25 | 26 | La instalación se hace en línea de comandos: 27 | 28 | ```zsh 29 | docker-compose up -d 30 | ``` 31 | Puedes verificar la instalación accediendo a: [http://localhost/info.php](http://localhost/info.php) 32 | 33 | ## Comandos disponibles 34 | 35 | Una vez instalado, se pueden utilizar los siguiente comandos: 36 | 37 | ```zsh 38 | docker-compose start # Iniciar el ambiente de desarrollo 39 | docker-compose stop # Detener el ambiente de desarrollo 40 | docker-compose down # Detener y eliminar el ambiente de desarrollo. 41 | ``` 42 | 43 | ## Estructura de Archivos 44 | 45 | * `/docker/` contiene los archivos de configuración de Docker. 46 | * `/www/` carpeta para los archivos PHP del proyecto. 47 | 48 | ## Accesos 49 | 50 | ### Web 51 | 52 | * http://localhost/ 53 | 54 | ### Base de datos 55 | 56 | Existen dos dominios para conectarse a base de datos. 57 | 58 | * `mysql`: para conexión desde los archivos PHP. 59 | * `localhost`: para conexiones externas al contenedor. 60 | 61 | Las credenciales por defecto para la conexión son: 62 | 63 | | Usuario | Clave | Base de datos | 64 | |:---:|:---:|:---:| 65 | | dbuser | dbpass | dbname | 66 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | volumes: 4 | mysql-data: 5 | name: ${PROJECT_NAME}-data 6 | 7 | networks: 8 | network-id: 9 | name: ${PROJECT_NAME}-network 10 | 11 | services: 12 | mysql: 13 | build: 14 | context: ./docker/mysql 15 | args: 16 | mysql_version: ${MYSQL_VERSION} 17 | container_name: ${PROJECT_NAME}-mysql 18 | environment: 19 | MYSQL_DATABASE: ${MYSQL_DATABASE} 20 | MYSQL_USER: ${MYSQL_USER} 21 | MYSQL_PASSWORD: ${MYSQL_PASSWORD} 22 | MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD} 23 | volumes: 24 | - mysql-data:/var/lib/mysql 25 | ports: 26 | - "3306:3306" 27 | restart: always 28 | networks: 29 | - network-id 30 | 31 | php: 32 | build: 33 | context: ./docker/php 34 | args: 35 | php_version: ${PHP_VERSION} 36 | container_name: ${PROJECT_NAME}-php 37 | ports: 38 | - "${PHP_PORT}:80" 39 | volumes: 40 | - ./www:/var/www/html 41 | links: 42 | - mysql 43 | networks: 44 | - network-id 45 | -------------------------------------------------------------------------------- /docker/mysql/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG mysql_version 2 | 3 | FROM mysql:${mysql_version} 4 | -------------------------------------------------------------------------------- /docker/php/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG php_version 2 | 3 | FROM php:${php_version} 4 | 5 | # prepare install 6 | RUN apt-get update --fix-missing 7 | RUN apt-get install -y build-essential libssl-dev zlib1g-dev libpng-dev libjpeg-dev libfreetype6-dev 8 | 9 | # install zip extension 10 | RUN apt-get install -y libzip-dev && docker-php-ext-install zip 11 | 12 | # install mysql extension 13 | RUN docker-php-ext-install mysqli pdo pdo_mysql 14 | 15 | # install gd extension 16 | RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ 17 | RUN docker-php-ext-install gd 18 | 19 | RUN a2enmod rewrite 20 | RUN a2enmod headers 21 | -------------------------------------------------------------------------------- /www/info.php: -------------------------------------------------------------------------------- 1 |