In a previous post we created a Docker Container with Apache and PHP.
Now we are going to update that Container to include support to access Microsoft SQL Server databases.
The content of our updated Dockerfile is as follows:
FROM centos:7
# Install Apache
RUN yum -y update
RUN yum -y install httpd httpd-tools
# Install EPEL Repo
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# Install PHP
RUN yum -y install php72w php72w-bcmath php72w-cli php72w-common php72w-gd php72w-intl php72w-ldap php72w-mbstring \
php72w-mysql php72w-pear php72w-soap php72w-xml php72w-xmlrpc \
php72w-pdo php72w-pdo_dblib
# Update Apache Configuration
RUN sed -E -i -e '/<Directory "\/var\/www\/html">/,/<\/Directory>/s/AllowOverride None/AllowOverride All/' /etc/httpd/conf/httpd.conf
RUN sed -E -i -e 's/DirectoryIndex (.*)$/DirectoryIndex index.php \1/g' /etc/httpd/conf/httpd.conf
# Update FreeTDS Configuration
RUN sed -E -i -e 's/;([\t ]+)tds version = 4.2/ \1tds version = 7.1/' /etc/freetds.conf
EXPOSE 80
# Start Apache
CMD ["/usr/sbin/httpd","-D","FOREGROUND"]
You can also download this Dockerfile here
The changes on the Dockerfile are:
• The addition of the php72w-pdo, and php72w-pdo_dblib libraries.
• The update of the configuration of the FreeTDS software.
Now we create the Docker Image.
docker build -t image_apache .
Then we create the Docker Container.
Notice that we need to indicate the path of our local folder that will be served as the root of the Apache Web Server, which in this example is /path_to/my_website. Replace it with the location of your site's root folder..
docker run -tid -p 4000:80 --name=container_apache -v /path_to/my_website:/var/www/html image_apache
After the Docker Container is created, go to the url http://localhost:4000 to open the local website.
Check the Dockerfile on Github here.