Let's cut the fluff. Here is exactly what you need to know about this concept to survive in a real production environment.
1Compiling the Blueprint
Look, if you've ever dealt with this in production, you know exactly what the problem is. You have written a perfectly optimized, multi-stage Dockerfile. However, a Dockerfile is just a text document. It does nothing on its own. You must tell the Docker Daemon to read that text document and execute the instructions to physically create the Image on your hard drive. This is done using the docker build command. The command requires you to point it to the directory containing your Dockerfile, which is almost always the current directory (represented by a single dot .). This isn't just academic theory—understanding the *why* behind this is what separates junior devs from senior engineers. When you deploy to a cluster, this is the mechanic that prevents catastrophic failure.
# 1. Navigate to your project folder
> cd my-project
# 2. Tell Docker to build an image from the current directory (.)
> docker build .
Status: OK
Success: Operation completed.
2The Problem with Hashes
Look, if you've ever dealt with this in production, you know exactly what the problem is. If you just run docker build ., Docker will successfully build your image. However, it will assign it a random, cryptographic hash (like 7a8b9c0d1e2f) instead of a human-readable name. If you want to run your app, you would have to type docker run 7a8b9c0d1e2f. This is terrible for usability and impossible to manage. To solve this, we must 'Tag' our images with a human-readable name during the build process. This isn't just academic theory—understanding the *why* behind this is what separates junior devs from senior engineers. When you deploy to a cluster, this is the mechanic that prevents catastrophic failure.
> docker build .
Successfully built 7a8b9c0d1e2f
# Trying to remember the hash tomorrow...
> docker run 7a8b... wait, what was it?
Status: OK
Success: Operation completed.
3Tagging with -t
Look, if you've ever dealt with this in production, you know exactly what the problem is. To give your image a name, you use the -t (Tag) flag during the build process. The format is strictly docker build -t <repository>:<tag> .. The repository is the name of your app (e.g., my-api). The tag is the version (e.g., v1). If you run docker build -t my-api:v1 ., Docker builds the image and permanently labels it. You can now effortlessly spin up your app using docker run my-api:v1. This isn't just academic theory—understanding the *why* behind this is what separates junior devs from senior engineers. When you deploy to a cluster, this is the mechanic that prevents catastrophic failure.
# Syntax: docker build -t <name>:<version> .
> docker build -t my-api:v1 .
# Now you can use the human-readable name!
> docker run -p 8080:80 my-api:v1
Status: OK
Success: Operation completed.
