My Journey into Docker: Key Concepts and Commands Learned

·

2 min read

🚀 I'm excited to share that I've started my journey into learning Docker! Here's what I've learned so far from Harkirat's awesome video on YouTube: Watch Here. 🎥

Dockerfile Basics

FROM

  • Sets the base image for the Docker image.

WORKDIR

  • Sets the working directory inside the Docker image for command execution during the build process and also for the container runtime.

COPY

  • Copies files from the host machine's current directory to the Docker image's working directory during the build process.

RUN

  • Executes commands during the image build process.

CMD

  • Specifies the command to run when the container is up and running.

.dockerignore

The .dockerignore file is used to specify which files and directories should be ignored when building a Docker image. This helps in reducing the image size and build time by excluding unnecessary files.

Port Mapping in Docker

Port mapping allows a Docker container to communicate with the outside world by mapping container ports to host ports. This enables you to access services running in the container, like web servers or databases, from your local machine or other devices.

Example: docker run -p 8080:80 <tagname> maps port 80 in the container to port 8080 on the host.

Pushing & Pulling Docker Images

I've learned how to push images to DockerHub and pull/run them on an Azure VM. Here are some important commands:

  • Build an image: docker build -t <tagname> .

  • Run a container: docker run <tagname>

  • See running containers: docker ps

  • Stop a container: docker stop <container_id>

  • Push to DockerHub: docker push <accountname/reponame>

  • Pull from DockerHub: docker pull <accountname/reponame>

  • Login: docker login

Why Layers?

Layers enable caching, re-using layers, and faster build times. This makes the process of building and deploying Docker images more efficient.


Feeling more confident with Docker thanks to these insights! Can't wait to dive deeper. #Docker #Learning #TechJourney #DevOps


Feel free to comment if you have any questions or additional tips to share!

Â