Creating a container image in Docker is a fundamental skill for developers, especially when setting up a monitoring stack or any other application.
Whether you want to enhance your monitoring stack or want to containerize your applications, follow these clear and straightforward steps.
This blog post will guide you through the step-by-step process, complementing our video tutorial below.
REQUIREMENTS
Before diving in, ensure Docker is installed on your system. If you need guidance, refer to our posts on installing Docker on Ubuntu, macOS, or Windows. Additionally, understanding the basics of Docker and having a GitHub account will be beneficial.
Why Create a Container Image in Docker?
Building your Dockerfile, image, and container gives you full control over your application environment. It ensures consistency across different environments and enables seamless deployment.
By mastering this process, you empower yourself to manage dependencies efficiently and tailor your container to suit your specific requirements.
Step-by-Step Guide:
1. Clone the Repository
First things first, let’s get started by cloning the repository that contains our project files.
git clone https://github.com/thiagousa/youtube.git
cd youtube/11
2. Download the Ubuntu Image
We’ll begin by pulling the Ubuntu image required for our project.
docker pull nginx:1.25.4-alpine-slim
3. Create Docker Image
Now, let’s generate our application’s Docker image using the Dockerfile provided in the project.
docker build -t my-docker-image:1.0 .
4. Verify Image Creation
Confirm that the Docker image has been successfully created by listing all images.
docker images
5. Launch Docker Image
Deploy your Docker image, ensuring the necessary port is exposed for access.
docker run -itd -p 8888:80 --name=my-docker-image -v ./files:/usr/share/nginx/html/ my-docker-image:1.0
6. Validate Application
Use a web browser to check if the application is active and accessible at localhost:8888.
7. Additional Docker Commands
Here are some additional Docker commands for managing your containers and images:
- Stop running container:
docker stop my-docker-image
- Start a stopped container:
docker start my-docker-image
- Remove a container:
docker rm my-docker-image
- Remove an image:
docker rmi my-docker-image
UPDATING YOUR CONTAINER IMAGE
To update your container image, you might follow a similar process:
- Update your application’s code or Dockerfile.
- Build a new image with a new tag, for example, my-docker-image:2.0.
- Deploy the new image using the docker run command, adjusting the tag to match the new version.

CONCLUSION
Creating a Docker container image is a straightforward process that opens up numerous application deployment and management possibilities, mainly when dealing with a monitoring stack.
By following these steps, you’ll be able to containerize your applications efficiently and with confidence. For more detailed instructions and best practices on Docker and containerization, check out our other posts, such as Application Monitoring with Docker and Guide to Deploy Kubernetes.
