Many businesses rely on legacy applications, which may suffer from compatibility issues, maintenance challenges, and, frankly, inefficiency over time. Containerizing older applications with Docker is a pretty good way to modernize legacy systems, improve portability, and simplify deployment. This also helps you secure the app and overcome its vulnerabilities. However, keep in mind that not all old applications are worth containerizing.

👁 Top docker containers for productivity
4 ways to host Docker containers online

Docker makes app deployment easier, but where should you host your containers?

Assess the application

Make sure that the app is worth containerizing

Before you start, analyze the application you want to containerize. That means listing all the libraries, frameworks, and services the application relies on. You should also note the specific OS version, configurations, and any custom setups.

Finally, you have to clarify what you aim to achieve by containerizing (e.g., portability, easier updates, etc.). As I’ve mentioned above, not all applications can be containerized efficiently. For instance, if the app has certain dependencies on older processes that are no longer available, you won’t be able to achieve this.

Also, keep in mind that containers are usually made to run single processes, so it will be really difficult to containerize applications that rely on multiple processes or coupled services.

Create a Dockerfile

The complexity of the file varies with the complexity of your application

A Dockerfile defines the environment and instructions for building your container image. Here’s an example of a base structure of a Dockerfile:

# Base image
FROM [base-image]

# Metadata
LABEL maintainer="your-email@example.com"
LABEL version="1.0"
LABEL description="Containerized legacy application"

# Set environment variables
ENV APP_HOME=/app
ENV CONFIG_DIR=/config
# Install dependencies
RUN apt-get update && apt-get install -y \
dependency1 \
dependency2 \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR $APP_HOME
# Copy application files
COPY . .
# Expose ports
EXPOSE 8080
# Define volume mounts
VOLUME ["/data", "/logs"]
# Set startup command
CMD ["./start-application.sh"]

Keep in mind that the structure above is dedicated to simple build processes. If the old application requires complex build processes or compilation, you will have to use multi-stage builds.

Build the Docker image and test the container

Double-check the dependencies and environmental variables

After you have the Dockerfile ready, it’s time to build the image of your application. Start by placing the Dockerfile in the root directory of your application code. To build the Docker image, run the docker build -t your-app-name Dockerfile-path command. That will assign a name to your image and indicate the folder where you’ve saved the Dockerfile.

To test if the application is working, you have to run the container using the docker run -d --name your-container-name your-app-name command. If something is wrong, you might want to run the docker logs your-container-name command to check the logs and troubleshoot any problems. Of course, you have to replace your-app-name and your-container-name with the actual names in the Docker commands.

You may usually face issues with missing dependencies or configuration errors due to improperly set environmental variables. Also, make sure that you have the proper file permissions.

Create volumes and add them to your container

Only if you need to store generated data from the app

If the app you containerized generates data that you have to store, such as a database or a service, you have to create volumes. To do that, you can use the docker volume create app-data command.

Of course, after that, you have to attach the volume to your container using the following command:

docker run -d --name your-container-name -v app-data:/path/to/data your-app-name

If the image is too big, try to remove unnecessary packages throughout the build process. You can also reduce the image size by separating the build environment from the runtime environment.

Push the image to a registry and deploy the app

This is how you share the app

If the app is working, and it’s properly containerized, you can share it by pushing the image to a Docker registry. After logging into your Docker hub, tag the image using the docker tag your-app-name your-dockerhub-username/your-app-name command.

Then, you can finally push the image with the docker push your-dockerhub-username/your-app-name command.

Finally, you can deploy and run the app using the following commands:

docker pull your-dockerhub-username/your-app-name
docker run -d your-dockerhub-username/your-app-name

Again, these are instructions for simple deployments and apps. If you’re dealing with more complex deployments, you may need to use Docker Compose or Kubernetes instead.

Docker

Why should you containerize your old apps?

By containerizing older applications, you will breathe new life into your older applications. Also, they are easier to manage, deploy, and maintain after containerization. This is also a way to secure and protect your apps from breaches.

However, the most important step of this process is the initial assessment of the app. Some apps may be too difficult to containerize or become too slow or unreliable after containerization. So, make sure that it’s worth the effort and that you get real value from the containerization.