Docker Quick Start (3)-Share images on Docker Hub

Prerequisites

In the second part , follow the steps to build the image and run it as a containerized application.

Introduction

You have now built the containerized application described in Part 2 on your local development machine . The final step in developing containerized applications is to share images on a registry like Docker Hub so that they can be easily downloaded and run on any target machine.

Set up your Docker Hub account

If you don't have a Docker ID, follow the steps below to create one. Docker ID allows you to share images on Docker Hub.

  • Visit the Docker Hub registration page.
  • Fill out the form and submit to create your Docker ID.
  • Verify your email address to complete the registration process.
  • Docker or click on the toolbar icon in the system tray, then click Login / Create ID Docker ( Sign in / the Create Docker ID ).
  • Fill in your new Docker ID and password. After you have successfully authenticated, your Docker ID will appear in the Docker Desktop menu, replacing the "Login" option you just used.

You can also enter the command line docker loginlogin Docker Hub.

Create a Docker Hub warehouse and push your image

Before creating a warehouse, make sure you have set up your Docker Hub account and connected it to Docker Desktop.

Now, let's create the first warehouse and push the bulletin board image to Docker Hub.

  1. Click the Docker icon in the menu bar and navigate to Repositories> Create . You will be redirected to the Create Repository page on Docker Hub .

  2. Enter the name of the warehouse bulletinboardand at the bottom of the page click on the Create . Don't fill in any other details for now.Insert picture description here

  3. You are now ready to share the image on Docker Hub, but you must do one thing first: the image must be properly namespaced before it can be shared on Docker Hub. Specifically, you must be a mirror named:
    <Your Docker ID>/<Repository Name>:<tag>.

    Make sure you are in the terminal or in PowerShell node-bulletin-board/bulletin-board-app, and then run directory:

    docker tag bulletinboard:1.0 <Your Docker ID>/bulletinboard:1.0
    
  4. Finally, push your image to Docker Hub:

    docker push <Your Docker ID>/bulletinboard:1.0
    

    Visit your repository in Docker Hub , and you will see your new image there. Remember, the Docker Hub repository is public by default.

    Trouble with push? Remember, you must log in to Docker Hub via Docker Desktop or the command line, and you must follow the steps above to name your image correctly. If the push seems to work, but you cannot see the new image in Docker Hub, please refresh your browser after a few minutes and check again.

in conclusion

Now that your image is ready to be used on Docker Hub, you can run it anywhere. If you try to use it on a new machine that does not already have it, Docker will automatically try to download it from Docker Hub. By moving the image in this way, you no longer need to install any dependencies other than Docker on the machine where you want to run your software. The dependencies of containerized applications are completely encapsulated and isolated in your image. You can use the Docker Hub described above to share the image.

Another thing to remember is: Currently, you just pushed your image to Docker Hub, what about your Dockerfile? A key best practice is to keep them in version control, possibly with the source code of the application. You can add a link or comment to the description of the Docker Hub repository to indicate where to find these files. This will not only save a record of how the image was built, but also a record of how the image was run as a complete application.

What to do next

We recommend that you take a look at the topics in Develop with Docker and learn how to use Docker to develop your own applications.


Author: Docker's official website
translator: Technical Zemin
Publisher: Technical Verses
links: English text

Guess you like

Origin blog.csdn.net/weixin_47498376/article/details/107047145