Create a Dockerfile

Push image to Docker Hub

  1. Log in to Docker Hub
    • Make sure you have a Docker Hub account. If not, create one at Docker Hub.
    • Log in using the Docker CLI:
      docker login
    • Enter your username and password when prompted.

  1. Tag the Image
    • Docker images must have a tag that includes your Docker Hub username to push to your repository.
    • For example, if your Docker Hub username is yourusername and you want to push ocr-docker:v1, tag the image:
      docker tag ocr-docker:v1 yourusername/ocr-docker:v1

  1. Push the Image
    • Push the tagged image to Docker Hub:
      docker push yourusername/ocr-docker:v1

  1. Verify the Image on Docker Hub
    • Go to your Docker Hub account and check under Repositories to confirm that the image was successfully pushed.

Using the Image

  • Once the image is on Docker Hub, anyone with Docker installed can pull and use it:
    docker pull yourusername/ocr-docker:v1
    docker run yourusername/ocr-docker:v1

Multi-platform support

Faster Multi-Platform Builds: Dockerfile Cross-Compilation Guide

  • In Docker, TARGETARCH is a built-in build argument that represents the target architecture (e.g., linux/amd64, linux/arm64, etc.) for the image you are building. This is particularly useful when building multi-architecture images using Docker’s Buildx feature. Example:
# syntax=docker/dockerfile:1
FROM --platform=$BUILDPLATFORM alpine:latest
 
ARG TARGETARCH
 
RUN echo "Building for architecture: $TARGETARCH"
 
# Copy binary depending on the target architecture
COPY --from=builder /binaries/$TARGETARCH/mybinary /usr/local/bin/mybinary

Multi-architecture builds: To build images for multiple architectures simultaneously, use the docker buildx build command with the —platform flag. This will automatically set the TARGETARCH argument for each build.

  • Create a builder image as building multi-platform images is currently only supported when using BuildKit with docker-container and kubernetes driversbash
docker buildx create --use
cool_sanderson
docker buildx build --platform linux/amd64,linux/arm64 -t myimage:latest .