User Tools

Site Tools


Sidebar

docker:build_create_run_image_phpinfo

This is an old revision of the document!


Build and modify PHP-7-Apache Docker Image

To build and modify docker image create new folder in your Linux Docker machine

[root@localhost v1]# ll /root/Docker_Php_Deploy/v1/
total 20
-rwxrwxr-x 1 root root 239 Mar  5 13:06 000-default.conf
-rwxr-xr-x 1 root root 300 Mar  5 14:24 Dockerfile
-rw-r--r-- 1 root root 432 Mar  5 11:22 howto.txt
-rwxr-xr-x 1 root root 242 Mar  5 14:23 index.php
-rwxrwxr-x 1 root root 164 Mar  5 13:36 start-apache
[root@localhost v1]#

The php:7-apache image set the Apache public directory to /var/www/html. However, in this case, following Laravel’s conventions, we need to set it to the /var/www/public. One way to achieve this is by setting up a virtual host configuration. Create a file called “000-default.conf” with the following contents:

# 000-default.conf
 
<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/public
 
  <Directory /var/www>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

Apache, by default, listens on port 80 (HTTP), this isn’t a problem when running the server on your machine. But some cloud providers require that containers use different ports.

We’ll create a script to dynamically override Apache’s port when the container starts. Create a file called start-apache with the following contents:

#!/usr/bin/env bash
sed -i "s/Listen 80/Listen ${PORT:-80}/g" /etc/apache2/ports.conf
sed -i "s/:80/:${PORT:-80}/g" /etc/apache2/sites-enabled/*
apache2-foreground

And ensure the file is executable:

$ chmod 755 start-apache

We’re set to create a production-ready image. Create a file called Dockerfile.

In that folder we will need Dockerfile witch is required to build any Docker image:

docker/build_create_run_image_phpinfo.1583416797.txt.gz · Last modified: 2020/03/05 14:59 by admin