DEV Community

Ameh Mathias Ejeh
Ameh Mathias Ejeh

Posted on

1

Containerized a Simple Application using Docker.

Overview

I recently started learning docker and it was interesting. Docker uses client-server (docker-engine) architecture, it has its client components that talks to a server component using a restful API. A container is a special process running on your computer, all containers on a host share the operating system of the host.

Prerequisites

  • Docker CLI and Desktop Installed.
  • Node.js v22.14.0
  • Git

Setup Instructions

  • First, I wrote a simple application using node.js in app.js file

Image description

  • I dockerized the application, meaning I made a small change so that it can be run by docker by adding a simple dockerfile.

A dockerfile is a plain text file that includes instructions that docker uses to package up this application into an image.

Image description

  • To build the docker image, run the command
docker build -t hello-docker
Enter fullscreen mode Exit fullscreen mode

Image description

  • To run this image to on any computer running docker
docker run hello-docker
Enter fullscreen mode Exit fullscreen mode
  • Once we have the image; we can push it to DockerHub. DockerHub to docker is like GitHub to Git. It is a storage for docker images that anyone can use. The image must be tagged before pushing.
docker tag <image-id> <dockerhub-username>/<repository-name>:<tag>
Enter fullscreen mode Exit fullscreen mode
  • Then push
docker push amehmathias/hello-docker:latest
Enter fullscreen mode Exit fullscreen mode

Image description

  • Once our application image is on DockerHub, then we can put it on any machine running docker.

Image description

Challenge faced

I encountered an error while trying to push my application image to DockerHub without first tagging it

Image description

Based on the error message on the terminal, I noticed I have to tag my image before pushing it.

DevCycle image

Fast, Flexible Releases with OpenFeature Built-in

Ship faster on the first feature management platform with OpenFeature built-in to all of our open source SDKs.

Start shipping

Top comments (2)

Collapse
 
artjoker_dev_team profile image
Artjoker_Dev_Team

Great post, really! We’ve had similar experiences with Docker. One thing we always emphasize is the importance of version control for Docker images, especially when working in multiple environments. It really helps to avoid unexpected issues during deployment. Also, tagging images before pushing them to DockerHub is something that can easily slip through the cracks, a mistake we’ve made too. Thanks for sharing your journey and insights, it’s always helpful to see how others tackle common challenges. Keep it up)

Collapse
 
ameh_mathias profile image
Ameh Mathias Ejeh

Thank you for your insight.