With docker we can run a container in several ways, we can download ready-made images that have the programs we want, as well as we can build our own images from a Dockerfile.
As I’m studying docker, I created an image that builds a PHP development environment with the Oracle database libraries installed.
I will be making available the image and the Dockerfile with the steps if you want to create your own image or modify it according to your needs.
I will not show how to install docker in you machine, there are a lot o materials about that on the internet, after install the docker, choose one option below.
Option 1 – Running from a pre-built image
Using the commands below, we will create a directory in the home directory, this directory will be where your php files will stay, and after we create an info.php file to check later in the browser the PHP information, and then just run the container:
mkdir ~/html_dev printf "<?php \nphpinfo();" > ~/html_dev/info.php sudo docker run -d -p 8080:80 -v ~/html_dev:/var/www/html:rw rosembergmcz/php7_pdo_oci_oracle11:v2
With the command above docker will download the image if it does not exist on your machine, it can take a while, after download the image the docker will run the container and associate the port of apache on port 8080, after that, you just need to go in the browser and access the address: https://localhost:8080/info.php. Soon you already have a container configured with PHP7 and PDO OCI and Oci8 ready to use. The ~/html_dev/ directory will be the place where you use to work and put your PHP files.
Option 2 – Create a image from a Dockerfile
Let’s now to the second option that is to build the image docker from a Dockerfile, I made available in GitHub a project containing the Dockerfile and the files needed to build the image.
Let’s start downloading the project using git and after that go to the directory created with the commands below:
mkdir ~/docker_project_php git clone https://github.com/rosemberg-al/docker-php7-pdo_oci-oci8.git ~/docker_project_php cd ~/docker_project_php
You can now review the files, especially the Dockerfile that is at the root of the project. In order for docker to construct an image as instructed by Dockerfile, just type:
sudo docker build -t a_name_that_you_want .
It is important to note that you should keep the dot ( . ) After the image name, this dot indicates that the command should use the contents of the current directory. After the creation process, if it has successfully occurred the final message will look like:
Successfully built cbc16b8517e3 Successfully tagged a_name_that_you_want
Now, just run a container with the image created with the command below that looks a bit like the command we used in the first option. We will now change the name of the image to be used to create the container.
mkdir ~/html_dev printf "<?php \nphpinfo();" > ~/html_dev/info.php sudo docker run -d -p 8080:80 -v ~/html_dev:/var/www/html:rw a_name_that_you_want
After that just go to the browser and access the address: https://localhost:8080/info.php. Now you already have a container configured with Apache, PHP7 and PDO OCI and Oci8 ready to use.
If you do not want to use a container and install it on your server without the use of docker, you can also consult this other post that I published previously on the subject.