How do you push a locally built image to a registry?
Tag the image with the registry's full name, log in with docker login, then run docker push. The tag must include the registry host and repository name, or Docker pushes to Docker Hub.
Explain it simply
Sending a parcel needs the right address on the label. In Docker the tag is the label: it says which registry, which repository, which version.
Steps: build the image, docker tag myapp:latest registry.example.com/team/myapp:1.0.0 to add a second name pointing to the same image, docker login registry.example.com to authenticate, then docker push registry.example.com/team/myapp:1.0.0. Docker uploads only the layers the registry does not already have, so repeated pushes are quick. Anyone with access then runs docker pull with the same name.
In CI, log in with a token or service account, not your personal password, and tag with the Git commit SHA or a version so each push is traceable.
Example
docker build -t myapp:latest .
docker tag myapp:latest ghcr.io/shubham/myapp:1.0.0
echo $TOKEN | docker login ghcr.io -u shubham --password-stdin
docker push ghcr.io/shubham/myapp:1.0.0What to say in the interview
"I build, tag the image with the full registry path and a version, docker login, then docker push. Only missing layers are uploaded. In CI I authenticate with a token and tag by version or commit SHA."
Common mistakes
- Tagging only as myapp:latest, so the push targets Docker Hub or fails.