Skip to content

Working with Docker Images

Push and pull Docker images to/from TUKE Harbor Repository.


  • Push


    Upload images to repository.

  • Pull


    Download images from repository.

  • Tagging


    Proper version labeling.

  • CI/CD


    Pipeline automation.


Basic Workflow

graph LR
    A[Build] --> B[Tag]
    B --> C[Login]
    C --> D[Push]
    D --> E[Pull]
Step Command Description
1 docker build Create image
2 docker tag Label for repository
3 docker login Login
4 docker push Upload to repository
5 docker pull Download from repository

Creating a Docker Image

From Dockerfile

FROM python:3.11-slim
WORKDIR /app
COPY app.py .
CMD ["python", "app.py"]
docker build -t my-application:v1.0 .

From running container

docker commit <container-id> my-application:v1.0

Tag and Push

Tag the image

docker tag my-application:v1.0 repository.cloud.tuke.sk/my-project/my-application:v1.0

Format

repository.cloud.tuke.sk/<project>/<image-name>:<tag>

Parameter Description Example
project Project name in Harbor my-project
image-name Docker image name my-application
tag Version or label v1.0, latest, dev

Log in

docker login repository.cloud.tuke.sk

Push image

docker push repository.cloud.tuke.sk/my-project/my-application:v1.0

Successful upload

The push refers to repository [repository.cloud.tuke.sk/my-project/my-application]
v1.0: digest: sha256:abc123... size: 1234

Pull and Run

Pull image

docker pull repository.cloud.tuke.sk/my-project/my-application:v1.0

Run container

docker run -d repository.cloud.tuke.sk/my-project/my-application:v1.0

Advanced Usage

Multi-platform images

Build for multiple architectures (amd64, arm64):

# Create buildx builder
docker buildx create --name multiarch --use

# Build and push for multiple platforms
docker buildx build --platform linux/amd64,linux/arm64 \
  -t repository.cloud.tuke.sk/my-project/my-application:v1.0 \
  --push .

Multiple tags

# Tag image with multiple versions
docker tag my-application:v1.0 repository.cloud.tuke.sk/my-project/my-application:v1.0
docker tag my-application:v1.0 repository.cloud.tuke.sk/my-project/my-application:latest

# Push both versions
docker push repository.cloud.tuke.sk/my-project/my-application:v1.0
docker push repository.cloud.tuke.sk/my-project/my-application:latest

Multi-stage build (size optimization)

FROM golang:1.21 AS builder
WORKDIR /app
COPY . .
RUN go build -o app

FROM alpine:latest
COPY --from=builder /app/app /app
CMD ["/app"]

Docker Compose

docker-compose.yml

version: '3.8'

services:
  app:
    image: repository.cloud.tuke.sk/my-project/my-application:v1.0
    ports:
      - "8080:80"
    restart: unless-stopped

Running

docker login repository.cloud.tuke.sk
docker-compose pull
docker-compose up -d

Kubernetes

Create docker-registry secret

kubectl create secret docker-registry tuke-registry \
  --docker-server=repository.cloud.tuke.sk \
  --docker-username=ab123cd \
  --docker-password=your-password \
  --docker-email=ab123cd@tuke.sk

Deployment YAML

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-application
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-application
  template:
    metadata:
      labels:
        app: my-application
    spec:
      imagePullSecrets:
      - name: tuke-registry
      containers:
      - name: app
        image: repository.cloud.tuke.sk/my-project/my-application:v1.0
        ports:
        - containerPort: 80

CI/CD Integration

GitLab CI/CD

# .gitlab-ci.yml
variables:
  IMAGE_NAME: repository.cloud.tuke.sk/$CI_PROJECT_PATH:$CI_COMMIT_SHORT_SHA

build:
  stage: build
  image: docker:latest
  services:
    - docker:dind
  before_script:
    - docker login -u $HARBOR_USER -p $HARBOR_PASSWORD repository.cloud.tuke.sk
  script:
    - docker build -t $IMAGE_NAME .
    - docker push $IMAGE_NAME

GitHub Actions

# .github/workflows/docker.yml
name: Build and Push Docker Image

on:
  push:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Login to TUKE Harbor
        uses: docker/login-action@v2
        with:
          registry: repository.cloud.tuke.sk
          username: ${{ secrets.HARBOR_USERNAME }}
          password: ${{ secrets.HARBOR_PASSWORD }}

      - name: Build and push
        uses: docker/build-push-action@v4
        with:
          push: true
          tags: repository.cloud.tuke.sk/my-project/my-application:${{ github.sha }}

Harbor Web UI

Viewing images

  1. Log in to Harbor web UI
  2. Go to your project
  3. Click Repositories
  4. Select repository and view all tags

Deleting an image

  1. In the repository list, select a tag
  2. Click Delete
  3. Confirm deletion

Warning

Deleted images cannot be recovered!


Command Reference

# Login
docker login repository.cloud.tuke.sk

# Tag image
docker tag <local-image> repository.cloud.tuke.sk/<project>/<image>:<tag>

# Push image
docker push repository.cloud.tuke.sk/<project>/<image>:<tag>

# Pull image
docker pull repository.cloud.tuke.sk/<project>/<image>:<tag>

# List local images
docker images | grep repository.cloud.tuke.sk

# Logout
docker logout repository.cloud.tuke.sk

Best Practices

Versioning

Instead of latest, use specific versions: v1.0.0, 2024.1, git commit SHA.

Multi-stage builds

Use multi-stage builds to minimize image size.

Automation

Integrate build and push into CI/CD pipeline.

Documentation

Add README to images using LABEL in Dockerfile.

Security

Never store sensitive data (passwords, API keys) directly in Docker images!


Next Steps

  • Login


    Logging in to repository.

    Guide

  • FAQ


    Common questions.

    FAQ