USING IRONSECUREDOC

Docker Compose Environment Variables (Developer 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

Frequently Asked Questions

What is containerization?

Docker is an open-source system for application development, deployment, and running using containerization. Containers include applications and their dependencies, allowing them to run uniformly across different environments.

What are environment variables in container management?

Environment variables in Docker Compose are key-value pairs used to configure settings in a containerized application. They allow configurations like database credentials and API keys to be managed outside the application code.

How can you set variables in a container setup?

Environment variables can be set in Docker via Dockerfile, docker-compose.yml, at runtime with the docker run command, or using environment files. Each method allows different levels of configuration flexibility.

What is a secure document processing tool for containers?

IronSecureDoc is a tool for secure document processing in containerized applications. It supports features like document encryption, redaction, and digital signing, integrating seamlessly with Docker for deployment.

How does using configuration management tools simplify deployment?

Docker Compose simplifies application deployment by using environment variables to manage configuration settings. This separation of environment-specific details from the codebase allows easier scaling and configuration management.

Why separate configuration files in container setups?

Environment files are used with Docker to keep environment variables separate from the main configuration files, improving organization and allowing for easier management of different environments.

What are the features of a secure document tool for containers?

IronSecureDoc offers features such as 128- or 256-bit encryption, redaction, digital signing, a REST API for integration, and Docker integration for simplified deployment and scaling.

How is secure document processing set up in container environments?

IronSecureDoc is installed in a Docker environment by pulling the Docker image from the repository and running it with the docker container run command, specifying necessary environment variables for setup.

What command is used for running containers with secure document tools?

The command used to run a Docker container for IronSecureDoc is 'docker container run --rm -p 8080:8080 -e IronSecureDoc_LicenseKey=-e ENVIRONMENT=Development -e HTTP_PORTS=8080 ironsoftwareofficial/ironsecuredoc:latest'.

How do configuration variables improve security in container deployment?

Environment variables enhance security in Docker deployment by allowing sensitive information like API keys and passwords to be managed outside the application code, reducing the risk of exposure.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.
< PREVIOUS
Docker Container List (How It Works For Developers)
NEXT >
Docker Compose Build (Developer Tutorial)

Ready to get started? Version: 2024.10 just released

View Licenses >