Published writing
Blog
Browse recent posts, filter by category, and move through the archive five posts at a time.
Running Nginx + PHP over Docker
Running Nginx + PHP over Docker
Following up on the previous post, linked here, we will be extending it to include running PHP over Nginx's fastcgi system. We will start with the final DockerFile in the previous post.
#Author: Michael Harrison
#Purpose: Showing how to create a docker image and manually install nginx.
#Pulls the base Ubuntu Image from Docker Hub
From ubuntu
#Lets install NGINX
RUN apt-get -y update && apt -y install nginx
#Lets copy the local index.html to /tmp
COPY index.html /tmp/index.html
COPY default /etc/nginx/sites-available/default
#lets expose port 80
EXPOSE 80/tcp
CMD /usr/sbin/nginx && tail -f /dev/null
Installing PHP
Since we are not specifying a specific version of Ubuntu in the line From ubuntu it pulls the latest version. The latest version at the time of this writing is Ubuntu 20.04 which comes with the PHP 7.
Installing NGINX on Docker
Installing NGINX on Docker
What is Docker?
Docker provides the capability to package a utility and its dependencies in a file that is called a container. Containers can be easily installed and ran on other machines without having to worry about differences between their machine and yours. This also bring the benefit of allowing more apps to run on a single server since the dependencies for the utility are contained in the container.
The Dockerfile
Dockerfiles are text files that tell the Docker tool how to build the image. The files could contain the commands to install and configure Nginx for example.
Setting up the Dockerfile
We first specify what we want to base our image off of, which the first line From ubuntu, specifies. This tells the Docker system to use the base Ubuntu image from Dockerhub. It will download the base Ubuntu image and layer the following commands on top of the base image.
From ubuntu
The next thing that we will want to