Running Docker Application for Apache Webserver supporting PHP4

Posted on

Docker is a software used to run a specific application and isolated within a securely container which is equipped with the necessary libraries and package so that the application itself can run properly.

The need of running Apache Webserver with the older version of PHP is urgent since a web-based application which is developed with a certain framework, in this context Code Igniter (CI) is still running with the old version of CI 1.7.1.

An alternative solution rises by choosing to run the application in  Apache Webserver emulated by docker which is equipped with PHP version that support Code Igniter 1.7.1.

To be able to see the perfect or the suitable Webserver designed so that it will be able to run and to execute the application based on Code Igniter 1.7.1, below is the list of resource available in Docker Official Repositories.

Below is the attempt and effort to fullfill the scenario :

1. Make sure that the docker service has already been installed, enabled and run. For more information, it can be viewed by referring to this article titled ‘Install Docker in CentOS 7 via command line‘.

Below is the sample of execution of the above scenario :

[root@hostname ~]# docker run -d --name php4 -h php4 -p 80:80 cmfatih/php4 /usr/local/apache2bin/apachectl -D FOREGROUND
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.
[root@hostname ~]# 

2. In the above command’s execution, running docker has failed since the service itself hasn’t been started. Below is the process of starting docker :

[root@hostname ~]# systemctl start docker

3. Try to execute the command for starting the docker again, below is the commmand execution :

docker run -d --name container_name -p 80:80 image_name command
Description : 
docker : It is a command which is used to run docker
run : It is an additional command of docker to run a command in a new container
-d : It is an optional parameter to run the container in a detached mode or in a daemonized mode. It means the container act as a service or daemon.  
container_name : It is an argument given as the name of the created container
-p : It is an optional parameter to publish the container parameter to the host
80:80
image_name : It is the name of the image which is going to be loaded into the container
command : The name of the process or command which is executed by the container.  

Below is an example of the above command’s execution pattern :

[root@hostname ~]# docker run -d --name php4 -h php4 -p 80:80 cmfatih/php4 /usr/local/apache2bin/apachectl -D FOREGROUND
Unable to find image 'cmfatih/php4:latest' locally
Pulling repository docker.io/cmfatih/php4
ad1f698595e1: Pull complete
8dbd9e392a96: Pull complete
Status: Downloaded newer image for cmfatih/php4:latest
docker.io/cmfatih/php4: this image was pulled from a legacy registry.  Important: This registry version will not be supported in future versions of docker.
75cc8e56777f7e0b2282890423417727cc7c2ab2d2a6cb665a5048cce0355d4a
docker: Error response from daemon: driver failed programming external connectivity on endpoint php4 (33d0974147c80d1c52e891578e5abba7fbf4d5ec02fc3485febf02f53d7bc2e6): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use.
[root@hostname ~]#


Description : 
docker : It is the command to call docker
run : It is an additional command to tell docker to run a container
-d : It is an additional parameter to tell docker to make the running container as daemon, service or in a detached mode so that it can run in background. 
--name : It is an optional parameter to specify the name of the running container 
php4 : It is the value of the parameter --name and it is the name of the running container
-p : It is an optional parameter to publish the container port to host port 
80:80 : It is the port of the container which is 80 and it is mapped to the host port which is also has the same port and it is port 80
cmfatih/php4 : It is the name of the image which is going to be loaded to the container
/usr/local/apache2bin/apachectl -D FOREGROUND : It is the command which is going to be executed by the container.

4. The above command’s execution of Apache Webserver which is emulated by docker to run has failed since the assigned port for Apache Webserver which is port 80 has already been used by another process. Try to stop the already running process of Apache Webserver in the local server by typing the following command :

[root@hostname ~]# systemctl httpd stop
Unknown operation 'httpd'.
[root@hostname ~]# systemctl stop httpd
[root@hostname ~]#

5. After successfully released port 80 from the running service of local Apache Webserver, remove the container which has already been executed by docker. To remove a container, this article titled ‘Removing Container from Docker via Command Line‘ can be used as reference. Continue on to re-run the container using the above command to run container using docker.

6. Last but not least, below is the command to check whether the Apache Webserver which is emulated by docker has already run properly. This is the command :

dockerps -a

Below is the full output of the above command’s execution :

[root@hostname ~]# dockerps -a
-bash: dockerps: command not found
[root@hostname ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
75cc8e56777f        cmfatih/php4        "/usr/local/apache2bi"   2 minutes ago       Created                                 php4
[root@hostname ~]#

It means that there are already running process in docker which is ‘php4’.

Leave a Reply