Skip to content

Latest commit

 

History

History
136 lines (99 loc) · 3.03 KB

DockeHub-image.md

File metadata and controls

136 lines (99 loc) · 3.03 KB

Creating, pushing, updating, and adding tags to Docker images involves several steps. Here's a detailed guide on how to do each of these tasks.

1. Creating a Docker Image

Dockerfile

First, you need to create a Dockerfile that contains instructions for building your Docker image. Here’s an example of a simple Dockerfile:

# Use an official Python runtime as a parent image
FROM python:3.8-slim-buster

# Set the working directory
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80

# Run app.py when the container launches
CMD ["python", "app.py"]

Building the Docker Image

To build the Docker image, use the docker build command:

docker build -t your-dockerhub-username/your-image-name:tag .

For example:

docker build -t myusername/myapp:1.0 .

2. Pushing the Docker Image to Docker Hub

Log in to Docker Hub

First, log in to your Docker Hub account:

docker login

You will be prompted to enter your Docker Hub username and password.

Push the Image

To push your image to Docker Hub, use the docker push command:

docker push your-dockerhub-username/your-image-name:tag

For example:

docker push myusername/myapp:1.0

3. Updating the Docker Image

To update your Docker image, make changes to your code or Dockerfile and then rebuild the image using the docker build command with a new tag.

For example, if you made some changes and want to tag it as version 1.1:

docker build -t myusername/myapp:1.1 .

Then push the updated image:

docker push myusername/myapp:1.1

4. Adding Tags to an Existing Docker Image

You can tag an existing Docker image with a new tag using the docker tag command.

Tagging an Image

docker tag source-image:source-tag target-image:target-tag

For example, if you want to tag myusername/myapp:1.0 as myusername/myapp:latest:

docker tag myusername/myapp:1.0 myusername/myapp:latest

Push the New Tag

Finally, push the newly tagged image:

docker push myusername/myapp:latest

Complete Example

Here’s a complete example workflow:

  1. Create and build the Docker image:
    docker build -t myusername/myapp:1.0 .
  2. Log in to Docker Hub:
    docker login
  3. Push the Docker image:
    docker push myusername/myapp:1.0
  4. Make some changes and rebuild the image with a new tag:
    docker build -t myusername/myapp:1.1 .
  5. Push the updated image:
    docker push myusername/myapp:1.1
  6. Add a new tag to the existing image:
    docker tag myusername/myapp:1.1 myusername/myapp:latest
  7. Push the new tag:
    docker push myusername/myapp:latest

This workflow covers creating, pushing, updating, and tagging Docker images.