Dec 02, 2025
Jordana A. & Ariffud M.
5min Read
Docker containers let you efficiently manage applications across different environments. Continue reading to learn how to create a Docker container and unlock its full potential for streamlined development and deployment.
Creating a Docker container is a simple process:
Download free docker cheat sheet
A Docker container is a lightweight, standalone software package that includes everything needed to run an application: code, libraries, dependencies, and runtime.
Just as a physical container can be moved from a ship to a train to a truck without changing its contents, a Docker container lets you move an app from a developer’s laptop to a testing environment and into production without any changes.
This solves the classic “it works on my machine” problem.
For example, you can run a MySQL container to provide a portable database or a Node.js container for web apps.
Containers are based on Docker images, which act as blueprints. Each time you run an image, Docker creates a new container instance. Check out our guide on Docker image vs container to learn about their differences.
Before you start creating containers, make sure you have:
For Hostinger’s Docker VPS customers, Docker and all its required components are automatically installed during your server setup.
If you own one of our regular VPS plans, don’t worry. You can set it up yourself in just a few clicks:


Creating a Docker container involves four main steps. Below, we’ll cover everything from getting a base image to running and managing your new container.
A blueprint for your container, a Docker image contains the necessary files and instructions for running your app. You can create images from scratch, but it’s much faster to use official, pre-built images available on Docker Hub.
mkdir myapp && cd myapp
docker pull image_name
For example, to get the latest MySQL image:
docker pull mysql
docker images

If a pre-built image doesn’t fit your needs, you can create a custom one using a Dockerfile. This is a text document that contains all the commands needed to assemble an image.
Important! This step is only necessary for custom apps. If you’re using a pre-built image like MySQL directly, skip to the next step.
nano Dockerfile
# Use the official Python image from Docker Hub FROM python:3.8-slim # Set the working directory in the container WORKDIR /app # Install curl (just as an example of using RUN) RUN apt-get update && apt-get install -y curl # Expose the port that the HTTP server will run on EXPOSE 8000 # Start a simple HTTP server when the container runs CMD ["python", "-m", "http.server", "8000"]
Here’s a quick breakdown of the key commands:
Now it’s time to create the container. You’ll use two key commands: docker build to create an image from a Dockerfile, and docker run to create and start a container from an image.
docker build -t my-python-server .

docker run --name my-python-container -d -p 8000:8000 my-python-server
If you want to run the MySQL image you pulled earlier, use:
docker run --name my-mysql-container -e MYSQL_ROOT_PASSWORD=my-secret-password -d mysql

For both commands, –name assigns a custom name for easier management, and -d runs the container in detached mode (in the background).
Once your container is running, you can manage it with several useful commands.
docker ps

docker logs my-mysql-container
docker stop my-mysql-container
docker stats

For advanced container management, use the docker exec command. It lets you execute a command inside an already running container without disrupting its operation.
Docker containers offer significant advantages for developers and businesses by improving how applications are built, shipped, and run. Here are the main benefits:
For a closer look at how Docker containers power real-world applications, check out the top Docker use cases.
Following best practices ensures your Docker containers are efficient, secure, and easy to manage. These are especially useful in scenarios such as hosting sites and deploying apps.
RUN apt-get update && apt-get install -y python3 && rm -rf /var/lib/apt/lists/*
docker run --cpus=0.5 --memory=500m image-name
We’ve covered how to create, manage, and optimize Docker containers, which let you build more consistent, portable, and efficient applications. This foundation streamlines the development lifecycle and makes software deployment more reliable.
When you start working with multiple containers for a single app, consider exploring container orchestration. Tools like Docker Swarm and Kubernetes automate the deployment, scaling, and management of containerized apps.
Docker Swarm offers a simple setup and tight integration with Docker, and it works best for small to medium-sized clusters. Kubernetes, on the other hand, provides greater power and features, making it ideal for large-scale, production-grade deployments with advanced scheduling and self-healing capabilities.
The choice is yours: use Swarm for a lightweight, easy-to-use solution, or choose Kubernetes for maximum flexibility and scalability.