USING IRONSECUREDOC

Docker Compose Environment Variables (Developer Tutorial)

Published December 16, 2024
Share:

Introduction

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 effective.

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 Docker File

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

# Dockerfile
ENV APP_ENV=devepolment
ENV DATABASE_URL=postgres://user:password@db:1234/mydev
# Dockerfile
ENV APP_ENV=devepolment
ENV DATABASE_URL=postgres://user:password@db:1234/mydev
#Dockerfile
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'ENV APP_ENV=devepolment ENV DATABASE_URL=postgres: 'user:password@db:1234/mydev
VB   C#

The setting of environment variables with the values defined in the Docker file will automatically lead to 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
version:
'INSTANT VB TODO TASK: The following line uses invalid syntax:
''3.8' services: myapp: image: myapp:latest environment: - APP_ENV=development - DATABASE_URL=postgres: 'user:password@db:1234/mydev
VB   C#

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 Docker file.

docker run -e APP_ENV=development -e DATABASE_URL=postgres://user:password@db:1234/mydev:latest
docker run -e APP_ENV=development -e DATABASE_URL=postgres://user:password@db:1234/mydev:latest
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'docker run -e APP_ENV=development -e DATABASE_URL=postgres: 'user:password@db:1234/mydev:latest
VB   C#

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.

APP_ENV=production
DATABASE_URL=postgres://user:password@db:1234/mydev
APP_ENV=production
DATABASE_URL=postgres://user:password@db:1234/mydev
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'APP_ENV=production DATABASE_URL=postgres: 'user:password@db:1234/mydev
VB   C#

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

What is IronSecureDoc?

IronSecureDoc for Docker allows developers to easily add a secure document processing capability to their containerized applications. Finally having learned Docker, you are enabled to encapsulate your ASP.NET Core application with IronSecureDoc in a homogenous 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 below 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
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'docker pull ironsoftwareofficial/ironsecuredoc
VB   C#

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 below 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
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'docker container run --rm -p 8080:8080 -e IronSecureDoc_LicenseKey=<IRONSECUREDOC_LICENSE_KEY> -e ENVIRONMENT=Development -e HTTP_PORTS=8080 ironsoftwareofficial/ironsecuredoc:latest
VB   C#

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 - Let it publish 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 that access to the service inside the container by passing through this particular port is achieved.
  • ironsoftwareofficial/ironsecuredoc:latest - This is simply a Docker image. The docker proper will create the newest version of the image that is available from the registry of Docker for IronSecureDoc.

IronSecuredoc Container

IronSecureDoc's REST API lets users redact, certify, and encrypt documents after it is launched in Docker; this feature is also mentioned elsewhere. 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'
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'curl -X 'POST' \ 'http: -H 'accept: */ *' \ -H 'Content-Type: multipart/form-data' \ -F 'pdf_file=@test.pdf;type=application/pdf'
VB   C#

By doing this, IronSecureDoc will get 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 automatically separate 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. Though you can also utilize other high-performance libraries that IronSoftware 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

< PREVIOUS
Docker Container List (How It Works For Developers)
NEXT >
Docker Compose Build (Developer Tutorial)

Ready to get started? Version: 2024.10 just released

Free DownloadView Licenses >