To build a Docker image, use the following command:
docker build --platform=linux/amd64 -t my-image .docker build→ Command to build a Docker image.--platform=linux/amd64→ Ensures the image is built foramd64architecture, useful for compatibility (especially on Apple Silicon Macs which default toarm64).-t my-image→ Tags the image with the namemy-image..→ Specifies the current directory as the build context (should contain aDockerfile).
Once the image is built, push it to Docker Hub:
docker push my-imagedocker push→ Pushes the image to the Docker registry.my-image→ The name of the image to be pushed.
- Before pushing, ensure you are logged in to Docker Hub using:
docker login
- If pushing to a Docker Hub repository, use the format:
docker tag my-image my-dockerhub-username/my-image docker push my-dockerhub-username/my-image
- If using a private registry, specify the registry URL:
docker tag my-image my-registry.com/my-image docker push my-registry.com/my-image
# Login to Docker Hub
docker login
# Build the image for amd64 architecture
docker build --platform=linux/amd64 -t my-dockerhub-username/my-image .
# Push the image to Docker Hub
docker push my-dockerhub-username/my-image