- Hands-On Kubernetes on Windows
- Piotr Tylenda
- 514字
- 2021-06-24 16:54:04
Pushing an image to the Docker registry
Sharing container images using the registry is performed via an image push. This process uploads the required image layers to the selected repository in a registry and makes it available for pull by other users that have access to a given repository. In the case of Docker Hub, which we will use for this demonstration, your repositories will be public, unless you have a paid plan.
Pushing images to Docker Hub requires authentication. If you haven't already registered at Docker Hub, please navigate to https://hub.docker.com/ and follow the instructions there. After registration, you will need your Docker ID and password in order to log in to the services using the docker login command:
PS C:\WINDOWS\system32> 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: packtpubkubernetesonwindows
Password:
Login Succeeded
Throughout this book, we will be using the packtpubkubernetesonwindows Docker ID in order to demonstrate our examples. It is recommended that you create your own account to be able to fully follow the examples in this book. Follow these steps:
- The first step is to create an image that can actually be pushed to the registry. We will use the following Dockerfile to create the image:
FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-1903
WORKDIR /inetpub/wwwroot
RUN powershell -NoProfile -Command ; \
Remove-Item -Recurse .\* ; \
New-Item -Path .\index.html -ItemType File ; \
Add-Content -Path .\index.html -Value \"This is an IIS demonstration!\"
This Dockerfile creates an IIS web host image, which serves a minimalistic web page that displays This is an IIS demonstration!.
- Save the Dockerfile in your current directory. To build it, issue the following docker build command:
docker build -t <dockerId>/iis-demo .
Bear in mind that you have to supply your Docker ID as part of the repository name in order to be able to push the image to Docker Hub.
- After a successful build, you are ready to perform an image push to the registry. This can be performed with the docker push command:
docker push <dockerId>/iis-demo
The following screenshot shows the output of the preceding command:
Docker pushes the image as a set of layers, which also optimizes the push process if already known layers are being used. Also, note that in the case of Windows-based images, you will see a Skipped foreign layer message. The reason for this is that any layers that come from a registry other than Docker Hub, such as Microsoft Container Registry (MCR), will not be pushed to Docker Hub.
Now, you can also navigate to the Docker Hub web page and check your image details – for the example image, you can check it here: https://cloud.docker.com/repository/docker/packtpubkubernetesonwindows/iis-demo/. Any user that has access to your repository can now use the docker pull <dockerId>/iis-demo command in order to use your image.
You have successfully pushed your first image to Docker Hub! Now, let's take a look at pushing images to custom image registries.
- Learning Cython Programming(Second Edition)
- Testing with JUnit
- Web交互界面設(shè)計與制作(微課版)
- C語言程序設(shè)計學(xué)習(xí)指導(dǎo)與習(xí)題解答
- 自然語言處理Python進(jìn)階
- OpenCV Android Programming By Example
- Clojure High Performance Programming(Second Edition)
- 分布式數(shù)據(jù)庫HBase案例教程
- JavaEE架構(gòu)與程序設(shè)計
- 開源網(wǎng)絡(luò)地圖可視化:基于Leaflet的在線地圖開發(fā)
- HTML5+jQuery Mobile移動應(yīng)用開發(fā)
- Jenkins 2.x實踐指南
- 熱處理常見缺陷分析與解決方案
- C語言開發(fā)寶典
- 流程讓管理更高效:流程管理全套方案制作、設(shè)計與優(yōu)化