跳至页脚内容
使用 IRONSECUREDOC

Docker Compose 构建(开发者教程)

What is Docker?

Docker is an open-source platform that simplifies the process of developing, deploying, and running applications using containerization. Containers are ultralight, portable units that package an application along with its dependencies, enabling consistent execution across diverse environments, from a developer's local system to production servers. Unlike traditional virtual machines, containers utilize the host operating system's kernel, enhancing their speed and efficiency.

Docker Compose Build (Developer Tutorial): Figure 1

Docker offers a virtualized template through Docker images to create and manage sets of containers. It includes the Docker Hub, a form of container image repository. The great appeal of this technology is its scalability, portability, and efficiency, making it highly popular in DevOps and cloud-centric development workflows.

How does Docker work?

  • The Docker Daemon listens for requests from the Docker Client, which may include docker build, docker pull, or docker run.
  • Docker Daemon handles the creation, management, and monitoring of containers. It also retrieves the required Docker images from a registry, such as Docker Hub.
  • Using the downloaded image, the daemon creates an isolated container, effectively a running instance of the application.
  • Containers share the host machine's OS kernel but remain isolated from each other, enabling the software to operate in a unique environment with its dependencies.
+--------------------+
|   Docker Client    |
|  (CLI/API)         |
+--------------------+
          |
          v
+--------------------+               +---------------------+
|   Docker Daemon    |   -------->   |   Docker Registry   |
|  (manages resources|               |  (stores images)    |
|  & runs containers)|               +---------------------+
+--------------------+
          |
          v
+---------------------+
|      Container      |  
|  (App Instance)     |
+---------------------+
          |
          v
+---------------------+
| Docker Image        |  
| (App Blueprint)     |
+---------------------+

What is Docker Compose?

Docker Compose provides an easy way to manage a multi-container Docker application using a single file: docker-compose.yml. This YAML file enables the configuration of multiple services, specifying aspects like Docker images, environment variables, networks, and volumes. You can utilize Docker Compose commands such as docker-compose up or docker-compose down to manage all containers in an application with a single action.

+--------------------------+
|   docker-compose.yml     |  (Configuration file)
+--------------------------+
            |
            v
+----------------+    +----------------+    +----------------+
|   Service 1    |    |   Service 2    |    |   Service 3    |
|  (e.g. web)    |    |  (e.g. db)     |    |  (e.g. cache)  |
+----------------+    +----------------+    +----------------+
            |                  |                   |
            -----------------------------------------
                         Docker Application

Docker Compose is particularly advantageous for complex applications like microservices with numerous container instances. It is effectively used across development, testing, and production settings.

Create a New React JS application With ASP.NET Core

Follow these steps to create a new Visual Studio React application with an ASP.NET Core backend and add Docker support:

Prerequisites

  • Visual Studio: Ensure Visual Studio 2022 or newer is installed with necessary workloads:
    • Web development and ASP.NET
    • Node.js development (React)
    • Docker Support
  • Docker Desktop: Must be installed and running.

Create New Project

  1. Open Visual Studio and choose New Project from the menu.

    Docker Compose Build (Developer Tutorial): Figure 2

  2. Search for "React and ASP.NET Core Web Application" in the "Create a new project" dialog and select it. Click Next.

    Docker Compose Build (Developer Tutorial): Figure 3

  3. Provide a name for the project, select a solution name, and choose the save location. Click Next.

    Docker Compose Build (Developer Tutorial): Figure 4

  4. Ensure Docker Support is enabled. Select the desired framework and click Create.

    Docker Compose Build (Developer Tutorial): Figure 5

  5. After project creation, add Docker support by right-clicking the project node and selecting Add > Docker Support.

    Docker Compose Build (Developer Tutorial): Figure 6

  6. Choose the container name and type, then click Ok.

    Docker Compose Build (Developer Tutorial): Figure 7

Now that the newly created project is added to the Docker container, Docker Compose commands can run it. Below is a sample output generated from the React JS client-side code.

Docker Compose Build (Developer Tutorial): Figure 8

Below is the API server-side code executing from the Docker container.

Docker Compose Build (Developer Tutorial): Figure 9

IronSecureDoc

IronSecureDoc enables developers to efficiently embed secure document processing into containerized applications. With Docker's support, encapsulate your ASP.NET Core app using IronSecureDoc, encouraging seamless deployment and scaling. Build a Dockerfile to integrate IronSecureDoc with your ASP.NET Core app, along with necessary scripts or configurations.

Docker Compose Build (Developer Tutorial): Figure 10 - IronSecureDoc

Moreover, a docker-compose.yml file can outline service dependencies and environment variables for easy access, assisting in handling document security tasks efficiently in different deployment settings. Ensuring the install and configuration of IronSecureDoc, like Docker, is essential for delivering features like document encryption and redaction.

Installing and Running IronSecureDoc

Retrieve the IronSecureDoc Docker image with this command:

docker pull ironsoftwareofficial/ironsecuredoc
docker pull ironsoftwareofficial/ironsecuredoc
SHELL

Docker Compose Build (Developer Tutorial): Figure 11

After pulling the image, use the following command to launch IronSecureDoc in a new container:

docker container run --rm -p 8080:8080 -e IronSecureDoc_LicenseKey=<IRONSECUREDOC_LICENSE_KEY> -e ENVIRONMENT=Development -e HTTP_PORTS=8080 ironsoftwareofficial/ironsecuredoc:latest
docker container run --rm -p 8080:8080 -e IronSecureDoc_LicenseKey=<IRONSECUREDOC_LICENSE_KEY> -e ENVIRONMENT=Development -e HTTP_PORTS=8080 ironsoftwareofficial/ironsecuredoc:latest
SHELL

Docker Compose Build (Developer Tutorial): Figure 12

Using IronSecureDoc with Docker Container

IronSecureDoc's REST API allows document operations like redaction, certification, and encryption once installed and running in Docker. For more on API endpoints, check the documentation.

To encrypt a document, send a POST request to the IronSecureDoc API:

curl -X 'POST' \
  'http://localhost:8080/v1/document-services/pdfs/encrypt?user_password=demo' \
  -H 'accept: */*' \
  -H 'Content-Type: multipart/form-data' \
  -F 'pdf_file=@test.pdf;type=application/pdf'
curl -X 'POST' \
  'http://localhost:8080/v1/document-services/pdfs/encrypt?user_password=demo' \
  -H 'accept: */*' \
  -H 'Content-Type: multipart/form-data' \
  -F 'pdf_file=@test.pdf;type=application/pdf'
SHELL

This command submits the document to IronSecureDoc for encryption.

Conclusion

Integrating Docker Compose with IronSecureDoc greatly enhances the efficiency and reliability of applications requiring secure document handling. Docker Compose effectively manages multi-container applications, streamlining dependencies and services coordination, including IronSecureDoc, which ensures development environment consistency, simplifies configurations, and boosts scalability.

In this setup, developers can fully leverage document security features, like encryption and redaction, within a containerized framework. Overall, combining Docker Compose with IronSecureDoc enriches the development process, offering a secure, efficient method for handling sensitive documents in modern applications. For information on IronSecureDoc licensing, visit this page. Click here to explore more Iron Software products.

常见问题解答

什么是Docker以及它如何促进应用程序的部署?

Docker是一个开源平台,通过使用容器简化了应用程序开发和部署。容器是轻量级的、可移植的单元,将应用程序及其所有依赖项打包在一起,确保在各种环境中的一致执行。

Docker Compose如何帮助管理复杂的应用程序?

Docker Compose是一种使用'docker-compose.yml'文件管理多容器Docker应用的工具。它简化了服务、镜像、网络和卷的配置和协调,使得管理像微服务这样的复杂应用程序变得理想。

使用Docker在Visual Studio中创建React JS应用程序与ASP.NET Core的步骤是什么?

要使用Docker在Visual Studio中创建React JS应用程序与ASP.NET Core,请确保安装有Visual Studio 2022或更高版本,必要的工作负载和Docker Desktop。创建项目,添加Docker支持,并使用Docker Compose命令来管理应用程序。

IronSecureDoc如何与Docker集成以进行安全的文档处理?

IronSecureDoc可以通过拉取其Docker镜像并在容器内运行与Docker集成。此设置允许通过其REST API进行像加密和修订这样的安全文档处理操作,增强了容器化应用的安全性。

使用Docker Compose与IronSecureDoc进行文档处理的好处是什么?

将Docker Compose与IronSecureDoc集成提高了应用程序的效率和可靠性,通过在容器化环境中管理依赖项和服务。它确保了安全和可扩展的文档处理,这对于需要强大文档安全性应用程序至关重要。

如何将Docker支持添加到现有的Visual Studio项目中?

要将Docker支持添加到现有的Visual Studio项目中,右键点击项目节点,选择添加 > Docker支持,并选择相应的容器选项。这将Docker功能集成到您的项目中,允许进行容器化开发。

在Docker容器中运行IronSecureDoc的过程是什么?

要在Docker容器中运行IronSecureDoc,使用`docker pull`命令获取镜像,然后使用必要的环境变量(如许可证密钥和端口)执行`docker container run`。此设置有助于在容器内进行安全文档处理。

如何在Docker环境中使用IronSecureDoc加密文档?

可以通过向其API发送POST请求来使用IronSecureDoc加密文档。使用`curl`命令上传文档,指定本地文件路径和加密参数。在Docker容器内执行此操作以保护文档。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。