DEV Community

Cover image for Docker For beginners
Jibachh Singh
Jibachh Singh

Posted on

Docker For beginners

In the world of software development, deploying applications can be complex. Before the era of Docker, companies often struggled with ensuring that their applications would run consistently across different environments. Virtual machines can't solve the problem of applications running in every environment. That's why Docker comes in role.

Introduction of Docker.

Docker is an open -source platform used to build, ship, and run applications inside containers.
 
What is a Container? 

Think of a container as a digital "shipping box" for your software. When you need to transport items - like a car or a piano - you pack them securely into a box to ensure they reach their destination intact. Similarly, a container packages your source code, dependencies, and the necessary operating system components into one unit. This ensures that your website or application runs exactly the same way on a friend's computer as it does on yours.

Docker beginners to advanced?
In the world of software development, deploying applications can be complex. Before the era of Docker, companies often struggled with ensuring that their applications would run consistently across different environments. Virtual machines can't solve the problem of applications running in every environment. That's why Docker comes in role.
Introduction of Docker.
Docker is an open -source platform used to build, ship, and run applications inside containers. 

Here are some commands for Docker containers.
docker run
docker exec -it bash
<>
What is a Docker Image?
A Docker image serves as the blueprint for creating one or more Docker containers. Since images are immutable, any change to an application's configuration or code requires building a new image rather than modifying the existing one. This immutability ensures consistency, reproducibility, and reliable deployments across development, testing, and production environments.
Docker images are treated as versioned deployment artifacts. They are built through CI/CD pipelines, scanned for security vulnerabilities, tagged with immutable versions (such as Git commit SHAs or semantic versions), stored in container registries like Docker Hub or Amazon ECR, and promoted across environments without rebuilding. This "build once, deploy anywhere" approach ensures consistency, traceability, and repeatable deployments while minimizing configuration drift.
If you have a Dockerfile, then you can build it by using these commands : 
docker build -t application:v1 .
What is a Dockerfile?
A Dockerfile is a text-based document that's used to create a container image. 
Some of the most common instructions in a Dockerfile include:
FROM - this specifies the base image that the build will extend.
WORKDIR - this instruction specifies the "working directory" or the path in the image where files will be copied, and commands will be executed.
COPY - This instruction tells the builder to copy files from the host and put them into the container image.
RUN - This instruction tells the builder to run the specified command.
ENV - This instruction sets an environment variable that a running container will use.
EXPOSE - This instruction sets configuration on the image that indicates a port the image would like to expose.
USER - This instruction sets the default user for all subsequent instructions.
CMD ["", ""] - This instruction sets the default command a container using this image will run.
Here is an example of the Dockerfile.

FROM golang:1.26 
WORKDIR /app
 COPY . .
RUN go mod download 
RUN go build -o app 
EXPOSE 8080 
CMD ["./app"]
docker build -t go-web-app:v1 .
Here you built the first Docker image and know you run the containers by using this commands .
docker run -d -p 8080:80 go-web-app:v1

Top comments (0)