How PHP and Docker Works Simultaneously? - Part 2
Docker and PHP: Working with Both Simultaneously – Part 2
PHP/Opensource

Docker and PHP: Working with Both Simultaneously – Part 2

So, in previous part; we learnt about basic things related to Docker such as its meaning, machine launched and installation process, Server set up; number of servers required, developing new machine with Windows via Command Prompt and lots more. If you have missed the first part then click here.

In the end, we had a term “Docker Hub”. So, now here, we will know what this Hub is all about?

Let’s begin: Meaning of Docker Hub

It is useful when we need to create an image from scratch. It is a cloud service that is useful to developers for storing and distributing images. Here; images that can be used as a base for other images are to be found.

Docker Hub

Through the images stored on this hub; Docker image is available that is used to run PHP applications on Apache Server. This image can be found using the search box from the Hub’s main page.

This image installs Apache and PHP on Docker machine. If you use this image then you must follow below steps:

  • Docker Pull Command is used to get the image.
  • The effect of this command is that apache image is to be installed on Docker Machine. Before we move ahead; we must check that the Apache image is created without any container running.
  • To fulfill this; below mentioned commands can be used :
    Command: docker images
  • Now, we can run and test the image with this command.

    Docker run –d –p 80:80 tutum/apache-php

  • Then, open the browser and type this address in the address bar: http://192.168.99.102. This is the docker host which may be different in your test.
  • One can check to see the existing containers and one can see that one container is running:
    Command: docker ps
  • Run the docker image from Docker file for loading custom PHP application:

    The apache-php image can be used as a base image for custom PHP application. First of all, we need to create certain folders in our structure and one can see from the next images.

    One can create PHP application folder that has PHP Apps available in D:\ and it has the file as well as the sample folder. The sample folder contains PHP Script and info.php. The PHP Script, info.php offers information about PHP configuration.

    Before obtaining the image from “Dockerfile”, we must build that file. For that, we must navigate to its location and then execute the below command.

    Further, it is to be checked as to when php info image was created. For that, one must run the image command.

  • Push and Pull Docker image from Docker Hub: To do so, one must first start with the previous php machine.

    One needs to create an account in the Hub. Remember the user name and password as the same will be used to login to repository after pushing an image therein. Once the process stops, available tags can be found in repository as no tag was specified while pushing the image.

Take Away

So, from this article; you learnt lot of things about Docker such as pulling image from its Hub, Installing it on Windows etc. The most important thing is running a PHP Script inside Docker file.

Hope you liked this post. For more such details; stay tuned to Softqube Technologies; a PHP Web Development Company in India.

Hari Patel

Hari Patel

I am the Managing Director of Softqube Technologies Pvt. Ltd., a modern-day digital transformation, design and development service provider. We provide services to businesses of all verticals across the globe. I believe and live by a mission that I help more entrepreneurs to build, launch and grow profitable businesses.