Read | Practice | Advance
Here we are going to create three containers with three different Dockerfiles. There will be three different containers are: mysql as mysql_lara and this container for the mysql database and it will be using 5009 port, Laravel project as app_laravel and the project is in the same root directory called test-app which will be using 5011 port, http or php server as lara_servphp7 which will be using 5013 port. Lastly, we will create network which is using bridge network. However, creating the docker environment for Laravel as following -
version: '3' services: mysql_lara: build: ./mysql container_name: lara_mysql ports: - '5009:3306' environment: MYSQL_ROOT_PASSWORD: pass volumes: - ./initdb.d:/docker-entrypoint-initdb.d networks: lara: ipv4_address: 192.168.100.4 app_laravel: tty: true build: ./app_laravel container_name: test_laravel volumes: - ./test-app:/var/www/html:cached ports: - '5011:80' networks: lara: ipv4_address: 192.168.100.7 depends_on: - mysql_lara lara_servphp7: tty: true build: ./lara_servphp7 container_name: lara_servphp7 volumes: - /Users/hashimoto/git/soe_serv:/var/www/html - /Users/hashimoto/git:/var/git ports: - '5013:80' networks: lara: ipv4_address: 192.168.100.6 depends_on: - mysql_lara networks: lara: driver: bridge ipam: config: - subnet: 192.168.100.0/24
FROM php:7.2-apache RUN docker-php-ext-install mysqli RUN docker-php-ext-install pdo_mysql RUN apt-get update && apt-get install -y \ libssl-dev \ openssl \ ssl-cert \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ && a2enmod ssl \ && a2ensite default-ssl RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" RUN php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" RUN php composer-setup.php RUN php -r "unlink('composer-setup.php');" RUN cp ./composer.phar /usr/bin/composer COPY ./php.ini /usr/local/etc/php/php.ini
FROM mysql:5.7 COPY ./my.cnf /etc/mysql/conf.d/
[mysqld] character-set-server=utf8 sql_mode=
FROM php:7.2-apache #FROM php:7.2-fpm-alpine3.7 RUN docker-php-ext-install mysqli RUN docker-php-ext-install pdo_mysql RUN pecl install xdebug RUN docker-php-ext-enable xdebug RUN apt-get update && apt-get install -y \ wget \ vim \ libssl-dev \ openssl \ ssl-cert \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ && a2enmod ssl \ && a2ensite default-ssl RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" RUN php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" RUN php composer-setup.php RUN php -r "unlink('composer-setup.php');" RUN cp ./composer.phar /usr/bin/composer RUN a2enmod rewrite COPY ./php.ini /usr/local/etc/php/php.ini COPY ./000-default.conf /etc/apache2/sites-available/000-default.conf COPY ./apache2.conf /etc/apache2/apache2.conf
docker-compose up or docker-compose up -d
and open your browser and browse
https://localhost:5011
Finally, it can be said that installing docker and create docker images is simple and easier and it is totally independent platform to use multiple development tools thereby, it helps to reduce development and deployment Complexities.
Note: if there is some help needed for install to create docker image then feel free to contact ixora solution.
very nice