0
0
Dockerdevops~5 mins

Pushing images from CI in Docker - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you build software, you often create a package called a container image. Pushing images from CI means automatically sending these images to a storage place called a registry, so others can use them easily.
When you want to automatically update your app's container image after every code change.
When you need to share your container image with your team or deployment systems.
When you want to keep your images safe and organized in a central place.
When you want to avoid manual steps and speed up your release process.
When you want to use the latest image in your testing or production environments.
Commands
This command builds a container image named 'my-app' with the tag '1.0' from the current folder. It packages your app code and dependencies.
Terminal
docker build -t my-app:1.0 .
Expected OutputExpected
Sending build context to Docker daemon 5.12MB Step 1/5 : FROM python:3.10-slim ---> 123abc456def Step 2/5 : COPY . /app ---> Using cache ---> 789def123abc Step 3/5 : WORKDIR /app ---> Using cache ---> 456abc789def Step 4/5 : RUN pip install -r requirements.txt ---> Using cache ---> 321fed654cba Step 5/5 : CMD ["python", "app.py"] ---> Using cache ---> 654fed321cba Successfully built 654fed321cba Successfully tagged my-app:1.0
-t - Assigns a name and tag to the image for easy reference.
This command logs you into the container registry so you can upload images securely.
Terminal
docker login -u myuser -p mypassword registry.example.com
Expected OutputExpected
Login Succeeded
-u - Specifies the username for the registry.
-p - Specifies the password for the registry.
This command tags your local image with the registry address and your username, preparing it for upload.
Terminal
docker tag my-app:1.0 registry.example.com/myuser/my-app:1.0
Expected OutputExpected
No output (command runs silently)
This command uploads your tagged image to the registry so others can download and use it.
Terminal
docker push registry.example.com/myuser/my-app:1.0
Expected OutputExpected
The push refers to repository [registry.example.com/myuser/my-app] 1.0: Pushed
This command logs you out from the registry to keep your credentials safe after pushing.
Terminal
docker logout registry.example.com
Expected OutputExpected
Removing login credentials for registry.example.com
Key Concept

If you remember nothing else from this pattern, remember: build your image, log in to your registry, tag your image with the registry path, push it, then log out.

Common Mistakes
Trying to push an image without logging into the registry first.
The registry will reject the upload because it does not recognize you as an authorized user.
Always run 'docker login' with your credentials before pushing images.
Pushing an image without tagging it with the registry address.
Docker will try to push to the default Docker Hub instead of your intended registry, causing errors or pushing to the wrong place.
Tag your image with the full registry path before pushing.
Using the 'latest' tag unintentionally or without versioning.
It can cause confusion about which image version is deployed and may overwrite important versions.
Use explicit version tags like '1.0' to keep track of image versions.
Summary
Build your container image with 'docker build' and assign a clear tag.
Log in to your container registry using 'docker login' to authenticate.
Tag your image with the full registry path before pushing.
Push the image to the registry with 'docker push' so it can be shared.
Log out from the registry after pushing to keep credentials safe.