How to Dockerize PHP Barcode Reader on Ubuntu

When using PHP native extensions, you have to carefully match the right PHP version. Otherwise, it may cause a compatibility issue. In addition, the web server deployment of a PHP project with customized extensions is complicated as well. A proper solution for quickly experiencing a PHP project is to use Docker. In this article, I will demonstrate how to Dockerize the PHP barcode reader project built with Dynamsoft Barcode Reader SDK for Linux.

docker php barcode reader linux

Building Docker Image for PHP Barcode Reader

A Docker image with PHP and Apache

Create a Dockerfile and choose a suitable Docker image with PHP and Apache according to PHP Docker hub page:

FROM php:5.6-apache

Build the Docker image:

sudo docker build -t php-barcode-reader .

Run the image:

sudo docker run -p 2016:80 php-barcode-reader

Open Firefox to visit localhost:2016,  you will see the Apache homepage.

A Docker image with PHP barcode reader

Since Dynamsoft Barcode Reader supports PHP 5.3, 5.4, 5.5 and 5.6 for thread-safe and non-thread-safe, you need to check the relevant information firstly.

We can access the Docker container to run Bash, referring to exec of command line reference:

sudo docker exec -it container_id bash
php –v
php –i | grep Thread

docker container bash

Download the source code of PHP barcode reader and extract the package.

Create three folders config, libs, and src, and then copy corresponding resources to these folders:

docker project structure

Add extension path to php.ini:


Edit Dockerfile:

FROM php:5.6-apache

COPY config/php.ini /usr/local/etc/php/
COPY src/ /var/www/html/
COPY libs/ /usr/lib/

Save the Dockerfile and built the image again. Now if you run the Docker image, you will see the homepage of your PHP barcode reader:

linux php barcode reader

Tag the image and push it to Docker hub:

sudo docker tag php-barcode-reader dynamsoft/php-barcode-reader 
sudo docker push dynamsoft/php-barcode-reader

Docker Image