跳過到頁腳內容
使用 IRONSECUREDOC

從鏡像啟動 Docker 容器(開發者教程)

What is Docker?

Docker is an open-source platform that automatically deploys and manages applications within lightweight, portable containers. Containers package an application along with its dependencies, which include libraries and configuration files, so it can run consistently across different environments. This consistency makes development and testing more straightforward because applications can run identically on diverse systems—whether on a developer's laptop, a server, or a cloud environment. Scalability in application management means developing, shipping, and running containers efficiently, which Docker facilitates.

Docker Start Container From Image (Developer Tutorial): Figure 1 - Docker

Docker images make the specification of a consistent runtime environment much easier for developers. Most prebuilt images can be found in an open registry called Docker Hub, which developers can use directly or customize. For applications involving multiple containers, tools like Docker Compose orchestrate the container, whereas Kubernetes can manage even more complex scaling and automation. Docker has become an essential tool in software development and DevOps.

What is a Docker container?

A Docker container is essentially an application with all its dependencies—such as libraries, binaries, and configuration files—packed into a lightweight standalone executable entity. Containers designed in isolation run on top of a host operating system's kernel, avoiding interference from any other running software. Being easy to start, stop, or delete makes them ideal for testing, deployment, and scaling.

Docker container features

  • Isolation: Containers run in isolated environments; applications will not conflict with one another, even if they use different sets of dependencies or libraries.
  • Lightweight: Containers share the host operating system kernel, so they are small and have faster startup times than VMs.
  • Portability: Containers are deterministic and can run on any system using Docker, ensuring consistency across development, test, and production environments.
  • Scalability: Containers can be easily replicated and scaled, supporting fast deployment and management of microservices.
  • Resource Efficiency: Containers consume fewer resources than VMs, allowing for higher density and efficient utilization of computing resources.

What is a Docker image?

A Docker image is a blueprint for creating containers. It is read-only and layered, detailing the system files and dependencies needed to get an application running. Dockerfiles are used to create images, specifying how to build a Docker image, which might involve tasks such as installing software or copying files. Every change to a Dockerfile creates a new image layer, maintaining efficiency and modularity.

Features of a Docker Image

  • Multi-Level Stack: Images are built with layers using Dockerfiles. Each instruction in a Dockerfile adds a layer, so images should be optimized to rebuild only changed layers.
  • Reusability: Base images such as Ubuntu or Node.js can be reused across projects, saving development time and resources.
  • Versioning: Images can be tagged for versioning, making it easier to roll back to previous versions if needed.
  • Modularity: Changes to an image are incremental, enabling straightforward updates without rebuilding the entire image.
  • Available on Docker Hub: Public and private image registries facilitate easy sharing and deployment of images.

How to create a Docker container

The Dockerfile is a text file providing instructions to create your Docker image. In this file, you specify the base image, dependencies, application code, environment variables, and commands to run the application. Here is a simple example:

# Use an official Node.js runtime as a parent image
FROM node:18

# Set the working directory in the container
WORKDIR /app

# Copy package.json and install dependencies
COPY package.json /app
RUN npm install

# Copy the rest of the application code
COPY . /app

# Expose the application’s port
EXPOSE 3000

# Define the command to run the application
CMD ["node", "app.js"]

Build the Docker Image

Use the Dockerfile to create your Docker image. At the terminal command line, from the directory containing your Dockerfile, execute:

Make sure Docker Desktop is installed before executing the below command.

docker build -t my-app .
docker build -t my-app .
SHELL

This command creates an image named my-app. To confirm that it has been created, execute:

docker images
docker images
SHELL

Run the Docker Container

With an image, you can create a Docker container and then run it using the docker run command. The Docker daemon will start and monitor the process either in detached mode (background) or in the foreground.

docker run -d -p 3000:3000 --name my-running-app my-app
docker run -d -p 3000:3000 --name my-running-app my-app
SHELL
  • -d: Run the container in detached mode.
  • -p 3000:3000: Map the host's port 3000 to port 3000 in the container.
  • --name my-running-app: Assign a user-defined name to the container.

Verify Container

To check the running Docker containers, use:

docker ps
docker ps
SHELL

Docker Start Container From Image (Developer Tutorial): Figure 2 - Running Docker Containers

The above command shows the details of running containers, including container ID, name, image name, etc.

Stop and Remove Container

# Stop container
docker stop dazzling_snyder

# Remove container
docker rm dazzling_snyder
# Stop container
docker stop dazzling_snyder

# Remove container
docker rm dazzling_snyder
SHELL

Docker Start Container From Image (Developer Tutorial): Figure 3 - Stop Container

What is IronSecureDoc?

IronSecureDoc Docker is a containerized document processing solution by Iron Software that can automatically process documents in a Docker environment without human intervention. It offers complex document workflows and maximum data protection with encryption, digital signing, decryption, watermarking, and more for PDF and document files. It ensures consistent and scalable isolated deployments across platforms, making it suitable for DevOps and CI/CD pipeline integration.

Docker Start Container From Image (Developer Tutorial): Figure 4 - IronSecureDoc: The PDF Security and Compliance Server

This containerized approach enhances document handling in applications that require automation and high security, compatible with microservices and cloud-native environments. IronSecureDoc is especially useful for developers who create applications that require reliable automatic document processing in a controlled and portable Docker context.

Install and Run IronSecureDoc

Execute the following command from the Command Prompt or a terminal window to download the IronSecureDoc Docker image from the repository:

docker pull ironsoftwareofficial/ironsecuredoc
docker pull ironsoftwareofficial/ironsecuredoc
SHELL

Docker Start Container From Image (Developer Tutorial): Figure 5 - Download IronSecureDoc Image

After pulling the Docker image, initiate another command to start an IronSecureDoc container.

Creating a new Container for IronSecureDoc

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

The above docker run command creates a container instance of IronSecureDoc.

Docker Start Container From Image (Developer Tutorial): Figure 6 - New Container

Using IronSecureDoc container

IronSecureDoc enables users to install and run Docker to redact, certify, or encrypt files through its REST API.

Docker Start Container From Image (Developer Tutorial): Figure 7 - SecureDoc Web API

For instance, to encrypt a document, you can make 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 forwards the document to IronSecureDoc, which processes and encrypts the data accordingly.

Conclusion

In simple terms, Docker simplifies application deployment because a developer can create a container from an image, ensuring uniformity in a portable and scalable environment. This results in the efficient running of applications across platforms and facilitates resource utilization, enhancing DevOps and CI/CD pipelines.

Similarly, IronSecureDoc Docker utilizes Docker's containerized architecture to offer secure, automated document processing solutions. Together, Docker and IronSecureDoc provide powerful tools for building secure, scalable applications in modern software development. For more information on licensing IronSecureDoc, click this licensing page, and for details about the many products of Iron Software, visit the library suite page.

常見問題解答

什麼是 Docker,為什麼對開發者很重要?

Docker 是一個開源平台,自動化應用在容器中的部署和管理。它將應用及其依賴項打包,確保在不同環境中的一致運行,簡化了開發、測試和擴展。

Docker 映像如何促進應用部署?

Docker 映像作為只讀的藍圖來創建容器。它們定義了運行應用所需的系統文件和依賴項,從而實現輕鬆共享和部署。映像可存儲在如 Docker Hub 的註冊表中。

創建和運行 Docker 容器的主要步驟是什麼?

要創建和運行 Docker 容器,首先編寫一個 Dockerfile 指定基礎映像和依賴項。然後從 Dockerfile 构建 Docker 映像,並使用 docker run 命令創建並啟動容器。

IronSecureDoc 如何增強 Docker 中的文檔處理?

IronSecureDoc 是一種基於 Docker 的解決方案,通過加密和數字簽名等功能自動化文檔處理。它在 Docker 容器中確保安全、可擴展的工作流程,使其成為集成 DevOps 和 CI/CD 管道的理想選擇。

Docker 容器為應用開發提供了哪些好處?

Docker 容器提供了隔離、輕量運行、可移植性和資源效率。它們確保應用在不同環境中的一致運行,支持快速部署,簡化微服務的管理。

開發者如何確保使用 Docker 處理文檔的安全性?

開發人員可以使用 IronSecureDoc 在 Docker 容器中自動化安全的文檔處理。它提供加密、數字簽名及其他安全功能,增強文檔工作流程的保護和完整性。

Docker Hub 在容器部署中扮演什麼角色?

Docker Hub 作為預先構建的 Docker 映像的開放註冊表,允許開發者訪問和共享映像。這促進了應用的輕鬆定制和部署,加快了開發過程。

Docker 如何改善應用的可擴展性和效率?

Docker 改善可擴展性,允許容器的輕鬆複製和管理。這使應用能快速有效地擴展,優化資源利用並支持現代軟件開發實踐。

Dockerfile 在容器創建中有什麼用途?

Dockerfile 用於定義 Docker 容器的基礎映像、依賴項、應用代碼及執行命令。它是构建 Docker 映像的藍圖,隨後可用來創建容器。

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。