Docker Hub
Docker Hub is a cloud-based registry service from Docker that allows you to store, share, and manage your Docker images. It’s the default registry where docker pull looks for images if no other registry is specified.
Step-by-Step Guide to Pushing an Image
To share your Docker image on Docker Hub, you need to follow these steps.
1. Log in to Docker Hub
Use the docker login command to authenticate with your Docker Hub credentials.
docker loginYou will be prompted for your username and password.
2. Build and Tag Your Image
First, build your image using docker build. Then, you must tag it with your Docker Hub username and the repository name you want to use. This is a crucial step that associates the local image with your Docker Hub repository.
The standard format for a tag is <dockerhub_username>/<repository_name>:<tag>.
# First, build the image (example)
docker build -t my-local-image:1.0 .
# Then, tag it for Docker Hub
docker tag my-local-image:1.0 exampleuser/alpine-network:latest3. Push the Image
Once the image is correctly tagged, use docker push to upload it to your Docker Hub repository.
docker push exampleuser/alpine-network:latestAfter the push is complete, the image will be available on your Docker Hub profile.
Complete Example
# 1. Build the local image
docker build -t exampleuser/alpine-network:test1 .
# 2. Log in (if you haven't already)
docker login
# 3. Push the image (tagging was done implicitly in the build step here)
docker push exampleuser/alpine-network:test1Docker Build with Build-Time Arguments
You can pass build-time variables to your Docker build process using the --build-arg flag. This is useful for passing secrets like tokens or for customizing the build without hardcoding values in the Dockerfile.
docker build -t my-app --build-arg GITHUB_TOKEN=your_secret_token .Inside your Dockerfile, you would need to declare the ARG and then use it, typically in an ENV instruction or a RUN command.
ARG GITHUB_TOKEN
RUN echo "My token is ${GITHUB_TOKEN}"