USING IRONSECUREDOC

Docker Start Container From Image (Developer Tutorial)

Published December 16, 2024
Share:

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 that it can run consistently across different environments. This would make 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 would mean developing, shipping, and running containers efficiently, which Docker possesses.

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

In many respects, Docker images make the specification of a consistent runtime environment much easier for the developers. Most prebuilt images can be found in an open registry called Docker Hub, and developers use them directly or change contents according to their requirements. For applications, involving multiple containers, tools like Docker Compose to orchestrate the container whereas Kubernetes can manage even harder scaling and automation. Thus, Docker has become an essential tool in software development and DevOps.

What is a Docker container?

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

Docker container features

  • Isolation: The containers run in isolated environments; applications will not conflict with one another even if using a different set of dependencies or libraries.
  • Lightweight: As containers share the host operating system kernel, they are quite small and have faster startup times than VMs.
  • Portability: Containers are deterministic to run on any other system using Docker, hence consistent in the development, test, and production environment.
  • Scalability: Containers easily replicate and scale, and support microservice fast deployment as well as management.
  • Resource Efficiency: Containers consume fewer resources than VMs and therefore need a higher density with efficient utilization of computer resources.

What is a Docker image?

A Docker image, therefore, is an instruction to create a container; it is read-only and layered, which spells out the system file plus the dependencies needed to get an application running. Dockerfiles are used in forming images, which contain how to build a Docker image as cumbersome as installing the software or copying files would be. Every time this Dockerfile changes, a new image layer is created to keep things efficient and modular. It launches an image and it simply makes the container instance, based on that image, run it live.

Features of a Docker Image

  • Multi-Level Stack: Images are composed through layers, and with Dockerfile, every instruction incurs one layer of work. So, the build should be optimized because they need to rebuild only the changed layers.
  • Reusability: Base images such as Ubuntu or node can be reused from one project to another; this saves lots of development time and resources.
  • Versioning: The image can be tagged to support versioning. This will make it easier to roll back to a previous version if and when needed.
  • Modularity: All changes to an image are incremental, so updates are easy and even straightforward without building the complete image again.
  • Available on Docker Hub: Public and private image registries that make it easy to share and deploy images.

How to create a Docker container?

The Dockerfile is a text file that gives instructions on how to create your Docker image. In this file, you're supposed to have the base image, dependencies, application code, environment variables, and commands for running 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"]
# 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"]
#Use an official Node.js runtime as a parent image
#Set the working directory in the container
#Copy package.json and install dependencies
#Copy the rest of the application code
#Expose the application's port
#Define the command to run the application
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'FROM node:18 WORKDIR /app COPY package.json /app RUN npm install COPY. /app EXPOSE 3000 CMD ["node", "app.js"]
VB   C#

Build the Docker Image

Use the Dockerfile to create your Docker image. At the terminal command line from the directory that contains your Dockerfile execute the following command:

Make sure to install the Docker desktop before running the below code.

docker build -t my-app .
docker build -t my-app .
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'docker build -t my-app.
VB   C#

Creates an image named my-app. To confirm that it created an image you may execute Docker images.

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 in a detached mode or background running.

docker run -d -p 3000:3000 --name my-running-app my-app
docker run -d -p 3000:3000 --name my-running-app my-app
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'docker run -d -p 3000:3000 --name my-running-app my-app
VB   C#
  • -d: Detach the mode of a Docker container.
  • -map 3000:3000 Map the host to the container's port 3000 in the container.
  • --name my-running-app: Assigns a user-defined name to the container.

Verify Container

To check the running docker containers, use:

docker ps
docker ps
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'docker ps
VB   C#

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

The above code shows the details of the running container with 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
'Stop container
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'docker @stop dazzling_snyder docker rm dazzling_snyder
VB   C#

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 process documents automatically without any human intervention in a Docker environment. It offers complex document workflows and maximum data protection with encryption, digital signing, decryption, watermarking, and much more for PDF and document files. It ensures consistent and scalable isolated deployments across the platforms and, therefore, makes 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 requiring automation and high security compatibility as well as with microservices and cloud-native environments. IronSecureDoc is generally useful for developers who create and build applications that require reliable automatic document processing in a well-controlled and portable Docker context.

Install and Run IronSecureDoc

The following command should be executed from the Command Prompt or within an opened terminal window to download 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 Start Container From Image (Developer Tutorial): Figure 5 - Download IronSecureDoc Image

Following the pulling of the Docker image, we can initiate another command to start an operating container called IronSecureDoc.

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

The above Docker run command will create a container instance of the IronSecureDoc.

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

Using IronSecureDoc container

IronSecureDoc has enabled users in the installation and running in 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, when you would like to encrypt a document, you might do the following POST to 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'
'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#

This will automatically forward the document to IronSecureDoc, which will then encrypt the data accordingly.

Conclusion

In simple terms, Docker makes an application very smooth to deploy because a developer can create a container from an image. Therefore, there is uniformity in a portable and scalable environment. It makes it quite possible to start a Docker container from an image, leading to the very smooth running of applications across platforms and resulting in efficient resource utilization with flexible scaling to be quite beneficial to the DevOps and CI/CD pipelines.

On the same note, IronSecureDoc Docker uses Docker's architecture of containerized presentation that presents secure, automated document processing solutions. Together, Docker and IronSecureDoc provide powerful tools for building secure, scalable applications in modern software development. To know more about licensing Ironsecuredoc, click this licensing page and for details about the many products of Iron Software follow this library suite page.

< PREVIOUS
Docker Compose Network (How it Works for Developers)
NEXT >
Docker sign PDF (Developer Tutorial

Ready to get started? Version: 2024.10 just released

Free DownloadView Licenses >