Zum Fußzeileninhalt springen
VERWENDUNG VON IRONSECUREDOC

Docker Compose Umgebungsvariablen (Entwickler-Tutorial)

Deploying applications across different environments often leads to compatibility headaches. An app might run perfectly on a developer's machine but encounter issues in testing or production because of differences in operating systems, dependencies, or configurations. Docker solves this problem by packaging applications into self-contained units that include everything needed to run the app, ensuring it works consistently everywhere, from development to production.

Docker Compose brings powerful benefits to containerized applications, especially with its use of environment variables to simplify configuration across different setups. By allowing key settings to be managed outside the code, Docker Compose makes deploying complex applications more straightforward and secure. Building on these benefits, this article will also show how you can use IronSecureDoc for secure document processing, tapping into Docker Compose’s flexibility to handle configurations for encryption and redaction efficiently.

What is Docker?

Docker is an open-source system to ease application development, deployment, and running in a system through containerization. Containers are ultra-lightweight portable units that contain both an application and its dependencies so that they run uniformly everywhere—from the developer's machine to production servers. Containers share the kernel of the host's operating system compared to traditional virtual machines and, therefore, are much faster and more efficient.

Docker Compose Environment Variables (Developer Tutorial): Figure 1 - Docker webpage

This would mean a virtualized template in the form of Docker images to make and maintain this set of containers. Furthermore, the platform contains Docker Hub, which is in a way a container image repository. The beauty of this technology lies in its ease of use concerning scalability, portability, and efficiency, which is one reason it has gained such popularity among many DevOps and cloud-based development workflows.

What are Environment Variables in Docker-Compose?

In Docker, an environment variable in the form of a key-value pair is used to configure settings in the containerized application. Such variables can be useful to control the behavior of the application itself without modifying its code, since easily, configurations such as database credentials and API keys or environment modes (for example: development, production) may be changed.

In Docker, an environment attribute can be defined inside the Dockerfile, inside the docker-compose.yml file, or passed at runtime using the docker run command. With the use of environment variables, Docker allows consistent and flexible application deployment across different environments and manages sensitive data like passwords and API tokens more effectively.

How to Create Environment Variables in Docker?

We can define environment variables in Docker in quite a few ways. They can be defined with a Docker Compose file, the docker-compose.yml file, in an environment file, or even at runtime, as you are executing the docker run command. Remember, keeping environment variables separate from the main configuration file leads to easier organization of variables! Here is a list of the various methods that can be applied to define your variables.

Set Environment Variables in the Dockerfile

We can define environment variables directly in the Dockerfile, using the ENV instruction. This can be helpful if you want to include default values for the variables within your Docker image.

# Dockerfile
# Set the application environment
ENV APP_ENV=development
# Set the database URL
ENV DATABASE_URL=postgres://user:password@db:1234/mydev

The setting of environment variables with the values defined in the Dockerfile will automatically apply at the runtime of the container.

Set Environment Variables in Docker-Compose.yml

We can define environment variables for each service inside a docker-compose.yml with the help of the environment keyword. This is handy when you are using Docker Compose to manage a couple of services.

version: '3.8'
services:
  myapp:
    image: myapp:latest
    environment:
      - APP_ENV=development
      - DATABASE_URL=postgres://user:password@db:1234/mydev
version: '3.8'
services:
  myapp:
    image: myapp:latest
    environment:
      - APP_ENV=development
      - DATABASE_URL=postgres://user:password@db:1234/mydev
YAML

Set Environment Variables at Runtime

We can specify environment variables when running a container by using the -e flag along with the docker run command. This is good for transient and dynamic values, which you probably wouldn't add to the Dockerfile.

docker run -e APP_ENV=development -e DATABASE_URL=postgres://user:password@db:1234/mydev myapp:latest
docker run -e APP_ENV=development -e DATABASE_URL=postgres://user:password@db:1234/mydev myapp:latest
SHELL

Using Environment Files (.env)

We can store environment variables in a file like .env and load them into your Docker containers. In Docker Compose, we will refer to it with the env_file directive.

# .env file
APP_ENV=production
DATABASE_URL=postgres://user:password@db:1234/mydev
# .env file
APP_ENV=production
DATABASE_URL=postgres://user:password@db:1234/mydev
SHELL

We can manage multiple files, with environment variables outside the configuration files through the help of env files.

What is IronSecureDoc?

IronSecureDoc for Docker allows developers to easily add a secure document processing capability to their containerized applications. Having learned Docker, you can encapsulate your ASP.NET Core application with IronSecureDoc in a homogeneous environment that makes it easier to deploy and scale. To do this, you'll build a Dockerfile that orchestrates the construction of your ASP.NET Core application using the IronSecureDoc library and possibly other installation scripts or configurations needed to get things working.

Docker Compose Environment Variables (Developer Tutorial): Figure 2 - IronSecureDoc webpage

Besides, it includes a docker-compose.yml file declaring the service dependencies and environment variables and mapped ports to get on. This makes performing document security tasks much more accessible so your application can run efficiently and effectively in an environment other than the one used during development or production. Installation and Configuration of IronSecureDoc Like in the case of Docker, proper installation and configuration of IronSecureDoc will be needed to properly realize its capabilities: document encryption, redaction, etc.

Key Features of IronSecureDoc

IronSecureDoc offers a range of powerful features for PDF security and document management:

  • Encryption: Provides 128- or 256-bit encryption with password-based security to protect document confidentiality.
  • Redaction: Removes sensitive information, such as personal identifiers, to meet privacy standards and regulations.
  • Digital Signing: Supports digital signing and notarization with .pfx or .p12 certificates to ensure document authenticity.
  • REST API: Flexible API enables seamless integration with other software and workflows.
  • Docker Integration: Native support for Docker simplifies deployment and scaling for cloud or on-premises applications.

These features make IronSecureDoc an excellent choice for sectors handling sensitive documents, such as legal, healthcare, and finance.

Installing and Running IronSecureDoc

Step 1

To install IronSecureDoc, run the following command in a terminal window or Command Prompt to get the IronSecureDoc Docker image from the repository.

docker pull ironsoftwareofficial/ironsecuredoc
docker pull ironsoftwareofficial/ironsecuredoc
SHELL

Docker Compose Environment Variables (Developer Tutorial): Figure 3 - Console output for getting the IronSecureDoc image

Step 2

Once the IronSecureDoc image has been pulled, we can use the following docker-compose command to run the image into the Docker 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 Environment Variables (Developer Tutorial): Figure 4 - Console output from running the IronSecureDoc image

We use the docker container to run IronSoftware's official repository. The command line shown above breaks into several parts which are explained below.

Command Explanation

  • docker container run - This command uses the given image to construct and launch a new Docker container.
  • --rm - Automatically cleans up the container immediately once it stops running. It removes all the unused containers at the time of the completion of any process.
  • -p 8080:8080 - Publishes the container's port 8080, so you can access it on your machine from http://localhost:8080.
  • -e IronSecureDoc_LicenseKey=<IRONSECUREDOC_LICENSE_KEY> - Set an environment variable in the running container named IronSecureDoc_LicenseKey that lets you turn on and use licensed features of IronSecureDoc. Replace <IRONSECUREDOC_LICENSE_KEY> with your actual key.
  • -e ENVIRONMENT=Development - The environment variable is set to Development. This means that the container needs to be run in development mode. Normally, this container is used for the test or debug cases; other than that, it varies from nonproduction configurations.
  • -e HTTP_PORTS=8080 - This environment variable is used to specify that the container should expose and listen to port 8080 for HTTP traffic. It ensures access to the service inside the container by passing through this particular port.
  • ironsoftwareofficial/ironsecuredoc:latest - This is the Docker image. This specifies that the latest version of the image should be used from the Docker registry for IronSecureDoc.

IronSecuredoc Container

IronSecureDoc's REST API lets users redact, certify, and encrypt documents after it is launched in Docker. Here's a link to the API endpoints and documentation with Swagger UI, once you have launched IronSecureDoc in a Docker container: http://localhost:8080/swagger/index.html.

Docker Compose Environment Variables (Developer Tutorial): Figure 5 - Swagger UI for you to interact with API endpoints

From the above instance, we can send a POST request to the IronSecureDoc API to submit a document for encryption:

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

By doing this, IronSecureDoc will receive the document and properly encrypt it.

Conclusion

In sum, Docker Compose's environment variables allow the configuration of applications in a very flexible and efficient way since the configuration details are automatically separated from the application code. Consequently, managing different environments such as development, testing, and production is simpler, as only variables such as API keys, database credentials, and settings of an application need to be changed instead of its code.

Using Docker Compose to implement IronSecureDoc utilizes environment variables for securely handling the licensing information, for instance, the IronSecureDoc_LicenseKey, and also in specifying the HTTP ports or the environment mode preferred as either development or production using environment variables. Using environment variables for setup makes it simpler to deploy IronSecureDoc with much less cluttered and hard-to-scale configurations and boosts security.

Advanced features become accessible through a valid license of IronSecureDoc. The application of the tool is strictly dependent on certain terms of use. You can also utilize other high-performance libraries that Iron Software offers to make the development process easier and faster, providing robust functionalities in working with PDFs, text recognition, and barcodes for any conceivable application.

Docker Compose Environment Variables (Developer Tutorial): Figure 6 - IronSecureDoc licensing page

Häufig gestellte Fragen

Wie kann Docker Compose die Anwendungsbereitstellung verbessern?

Docker Compose verbessert die Anwendungsbereitstellung, indem es Umgebungsvariablen verwendet, um Konfigurationen extern zu verwalten. Dies ermöglicht eine einfache Skalierung und Anpassung über verschiedene Umgebungen hinweg, ohne den Anwendungscode zu ändern.

Welche Rolle spielen Umgebungsvariablen in Docker?

Umgebungsvariablen in Docker sind Schlüssel-Wert-Paare, die Anwendungseinstellungen unabhängig vom Code konfigurieren. Dadurch wird das sichere Management sensibler Informationen wie Passwörter und API-Schlüssel ermöglicht.

Wie integriert sich IronSecureDoc mit Docker für die sichere Dokumentenverarbeitung?

IronSecureDoc integriert sich mit Docker, indem es ein Docker-Image bereitstellt, das mithilfe von Docker-Befehlen abgerufen und ausgeführt werden kann. Es verwendet Umgebungsvariablen zur Konfiguration sicherer Dokumentverarbeitungsfunktionen wie Verschlüsselung, Schwärzung und digitale Signatur.

Was sind die Vorteile der Verwendung von Umgebungsvariablen in Docker Compose?

Die Verwendung von Umgebungsvariablen in Docker Compose ermöglicht eine flexible Konfigurationsverwaltung, verbesserte Sicherheit durch das Halten sensibler Daten außerhalb des Anwendungscodes und optimierte Bereitstellungsprozesse über verschiedene Umgebungen hinweg.

Wie kann man IronSecureDoc in einer Docker-Umgebung ausführen?

Um IronSecureDoc in einer Docker-Umgebung auszuführen, können Sie den Befehl docker container run --rm -p 8080:8080 -e IronSecureDoc_LicenseKey= -e ENVIRONMENT=Development -e HTTP_PORTS=8080 ironsoftwareofficial/ironsecuredoc:latest verwenden und notwendige Umgebungsvariablen für die Einrichtung angeben.

Welche Funktionen bietet IronSecureDoc zur Dokumentensicherheit?

IronSecureDoc bietet Funktionen wie Dokumentverschlüsselung, Schwärzung, digitale Signatur und nahtlose Integration mit Docker für sichere Dokumentenverarbeitung in containerisierten Umgebungen.

Wie werden Umgebungsvariablen in einem Docker Compose-Setup gesetzt?

Umgebungsvariablen können in Docker Compose unter Verwendung einer docker-compose.yml-Datei, Umgebungsdateien oder Laufzeitbefehlen gesetzt werden, was Flexibilität und Sicherheit in der Verwaltung von Anwendungskonfigurationen bietet.

Warum ist es wichtig, Konfiguration vom Code in Docker-Bereitstellungen zu trennen?

Die Trennung von Konfiguration und Code durch Umgebungsvariablen ist in Docker-Bereitstellungen wichtig, da sie die Sicherheit erhöht, die Verwaltung über verschiedene Umgebungen hinweg vereinfacht und das Risiko einer Offenlegung sensibler Informationen reduziert.

Curtis Chau
Technischer Autor

Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender ...

Weiterlesen