As we saw in Day-4 and Day-1 session about Docker Hub that, it's an image repository from where we can pull and push images. Let we discuss the same in little details.
Docker Hub is a service provided by Docker for finding and sharing container images. It is the world's largest library and community for container images, with over 100,000 images from software vendors, open-source projects, and the community.
Some of the key features of Docker Hub are:
• Repositories: You can create public or private repositories to store and manage your images. You can also push and pull images from Docker Hub using the docker push and docker pull commands.
• Official Images: You can pull and use high-quality container images provided by Docker that are curated, scanned, and signed. These images are based on popular software such as Ubuntu, Python, MySQL, etc.
• Verified Publisher Images: You can pull and use high-quality container images provided by external vendors that are certified by Docker. These images are based on commercial software such as MongoDB, Redis, NGINX, etc.
• Sponsored Open Source Images: You can pull and use high-quality container images from non-commercial open source projects that are sponsored by Docker. These images are based on projects such as Apache Airflow, Grafana, Prometheus, etc.
To use Docker Hub, you need to create a Docker ID and sign in to the service. You can also use the Docker Hub CLI tool (currently experimental) or the Docker Hub API to interact with Docker Hub programmatically.
Let we go step by step to work with Docker Hub and Try to push and pull the Image.
Step 1=> Check Pricing feature for Docker Hub Usage.
Just follow the URL to check the pricing plans for Docker Hub and choose best plan as per your requirements. Docker Hub Pricing Plans
Step 2=> Create Login ID for Docker Hub usage
Once pricing plan is decided, create a login with Docker Hub and that will be used to pull and push images on Docker Hub. Docker Hub Sign Up
Step 3=> Explore Docker Hub Homepage
Post login to Docker Hub click on explore and there you will find tons of images to download for creating containers.
Step 4=> Create a Public / Private repository.
You can create 1 private and more than 1 public repositories in Docker Hub for usages. Whereas Public repositories will be accessible by any docker Hub user, Private repositories will be accessible by you only.
Click on Repositories => Create repository => Enter Repository Name => Description => Select Public => Click on Create.
Step 6=> Push images to Docker Hub
PS D:\Docker> docker images REPOSITORY TAG IMAGE ID CREATED SIZE python_new_image 1.0 7e00745701d3 2 days ago 1.01GB old_python_image 1.0 7ce7e25dab6a 3 days ago 1.01GB PS D:\Docker> PS D:\Docker> docker push abhishek2023/python_repo Using default tag: latest The push refers to repository [docker.io/abhishek2023/python_repo] An image does not exist locally with the tag: abhishek2023/python_repo PS D:\Docker>
As we saw we got error now , this is because we don't have any image with name as "abhishek2023/python_repo" .
So either we need to rename current local image to this name, or we can create with the same name new image while running build command.
Let we rename existing local image to required image name as below.
PS D:\Docker> docker tag python_new_image:1.0 abhishek2023/python_repo:1.0 PS D:\Docker> PS D:\Docker> docker images REPOSITORY TAG IMAGE ID CREATED SIZE abhishek2023/python_repo 1.0 7e00745701d3 2 days ago 1.01GB python_new_image 1.0 7e00745701d3 2 days ago 1.01GB old_python_image 1.0 7ce7e25dab6a 3 days ago 1.01GB
Let's push again and see if this is working now.
PS D:\Docker> docker push abhishek2023/python_repo:1.0 The push refers to repository [docker.io/abhishek2023/python_repo] 75636b9c48d5: Preparing 1c702ba8e2e0: Preparing 56b9a4954d3a: Preparing b7023961c3b7: Preparing 9658baebb19e: Preparing f1acaab90728: Waiting 28218ecd8008: Waiting 2f66f3254105: Waiting a72216901005: Waiting 61581d479298: Waiting denied: requested access to the resource is denied PS D:\Docker>
I am getting " Error" this is due to privileges issue to docker Hub public repository.
Let we login with my Docker Hub ID and try again as below,
PS D:\Docker> docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: abhishek2023 Password: Login Succeeded Logging in with your password grants your terminal complete access to your account. For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/ PS D:\Docker> PS D:\Docker> docker push abhishek2023/python_repo:1.0 The push refers to repository [docker.io/abhishek2023/python_repo] 75636b9c48d5: Pushed 1c702ba8e2e0: Pushed 56b9a4954d3a: Mounted from library/python b7023961c3b7: Mounted from library/python 9658baebb19e: Mounted from library/python f1acaab90728: Mounted from library/python 28218ecd8008: Mounted from library/python 2f66f3254105: Mounted from library/python a72216901005: Mounted from library/python 61581d479298: Mounted from library/python 1.0: digest: sha256:1c3236dea9f75213df0a1c71564bdb69fe5b46426dbd40a24a80067b5a9d03a9 size: 2420 PS D:\Docker>
Step 7=> Let we login on Docker Hub and check if we have that image there as below.
As we see Image now available at Docker Hub.
Step 8=> Post successful push let me Logout from Terminal as below.
PS D:\Docker> docker logout Removing login credentials for https://index.docker.io/v1/ PS D:\Docker> PS D:\Docker>
Step 9=> We will now try to pull the image which we have added to Docker Hub repository. We will be following below steps.
Before that let we clean all old images.
PS D:\Docker> docker image rm -f 7e00745701d3 Untagged: abhishek2023/python_repo:1.0 Untagged: abhishek2023/python_repo@sha256:1c3236dea9f75213df0a1c71564bdb69fe5b46426dbd40a24a80067b5a9d03a9 Untagged: python_new_image:1.0 Deleted: sha256:7e00745701d3f4558abecbeabe80a7dbebe6f804173efe4d5ba97a5674b206f5 PS D:\Docker> PS D:\Docker> docker images REPOSITORY TAG IMAGE ID CREATED SIZE old_python_image 1.0 7ce7e25dab6a 3 days ago 1.01GB PS D:\Docker> PS D:\Docker> docker image rm -f 7ce7e25dab6a Untagged: old_python_image:1.0 Deleted: sha256:7ce7e25dab6a71c5311a0faa90c0ecde6bc1bf29066c7ff3e31aaa31632d4b85 PS D:\Docker> PS D:\Docker> docker images REPOSITORY TAG IMAGE ID CREATED SIZE PS D:\Docker>
Step 10=> Let we pull the image from Docker Hub as below.
PS D:\Docker> docker pull abhishek2023/python_repo:1.0 1.0: Pulling from abhishek2023/python_repo d52e4f012db1: Already exists 7dd206bea61f: Already exists 2320f9be4a9c: Already exists 6e5565e0ba8d: Already exists d3797e13cc41: Already exists 70f90dfe001b: Already exists bd75605de417: Already exists 3d0e1a4b14bc: Already exists 17cf7bd92cec: Already exists 8475e9db8219: Already exists Digest: sha256:1c3236dea9f75213df0a1c71564bdb69fe5b46426dbd40a24a80067b5a9d03a9 Status: Downloaded newer image for abhishek2023/python_repo:1.0 docker.io/abhishek2023/python_repo:1.0 PS D:\Docker> PS D:\Docker> PS D:\Docker> docker images REPOSITORY TAG IMAGE ID CREATED SIZE abhishek2023/python_repo 1.0 7e00745701d3 2 days ago 1.01GB PS D:\Docker>
Step 11=> Let we run this image to test the same as below using different scenario.
PS D:\Docker> docker run -it abhishek2023/python_repo:1.0 First number: 10 Second number: 90 Final Added Values as 100 PS D:\Docker> PS D:\Docker> docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 921aa0aa3497 abhishek2023/python_repo:1.0 "python add_num.py" 8 seconds ago Exited (0) 4 seconds ago affectionate_swartz PS D:\Docker> PS D:\Docker> docker run -it --rm abhishek2023/python_repo:1.0 First number: 10 Second number: 30 Final Added Values as 40 PS D:\Docker> PS D:\Docker> docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES PS D:\Docker>
Note: If we are not putting: tag number post images id/name it will always look for: latest tag in repository, so better to check with tag before pulling the image.
Now our Docker Hub practice completes here , let we move to data storage and management.
No comments:
Post a Comment