How to Run Web TWAIN App on Nginx within Docker Container

Dynamic Web TWAIN (DWT) is a Web-based TWAIN scanning solution, which could be deployed to Windows, Mac OS X, and Linux. Users could visit DWT apps via any HTML5-comptible Web browsers on Windows or Mac. To facilitate the process of Web project deployment, we can use Docker. In this post, I’m going to demo how to build a Web TWAIN docker image, and how to run the Web TWAIN “hello world” with commands in one line.

docker dynamic web twain

What is Docker?

Here is Docker’s definition:

“Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in.”

How to Build Docker Images with Your Resources and Code?

If you want to use Docker on Windows, make sure you have enabled CPU virtualization in BIOS before installing VirtualBox.

Install Docker

Ubuntu:

wget -qO- https://get.docker.com/ | sh
sudo service docker start

Windows:

Install docker-toolbox.

Web TWAIN Project with Dockfile

Download Dynamic Web TWAIN.

Find the “hello world” project.

dwt hello world

Copy the folder to a new Web project and rename HelloWorld.html to index.html.

Ubuntu:

docker project ubuntu

Windows:

docker project windows

According to the Nginx Docker tutorial, the Dockerfile is pretty simple:

FROM nginx
COPY . /usr/share/nginx/html

Reference Nginx and add the current folder to the path that within the Docker image. So what does Nginx Docker image do? You can refer to docker-nginx:

FROM debian:jessie

MAINTAINER NGINX Docker Maintainers "docker-maint@nginx.com"

RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
RUN echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list

ENV NGINX\_VERSION 1.9.5-1~jessie

RUN apt-get update && \\
    apt-get install -y ca-certificates nginx=${NGINX\_VERSION} && \\
    rm -rf /var/lib/apt/lists/\*

# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log
RUN ln -sf /dev/stderr /var/log/nginx/error.log

VOLUME \["/var/cache/nginx"\]

EXPOSE 80 443

CMD \["nginx", "-g", "daemon off;"\]

Build a Docker image

We can build the Docker image with following commands.

Ubuntu:

sudo docker build -t dwt .

Windows:

docker build -t dwt .

Check the images:

docker images

Tag and Push Docker Image

Tag the Docker image with namespace:

docker tag \[image id\] dynamsoft/dwt:latest

Login to Docker Hub:

docker login --username=username --password=password--email=email

Push the Docker image to your repo:

docker push dynamsoft/dwt

Use the Docker Image

Run following command:

docker run --name dynamsoft-dwt -d -p 2015:80 dynamsoft/dwt

Open Web browsers and visit http://host-ip:2015 on Windows or Mac OS X (Linux is not supported).

web twain scan

web twain result