As a lightweight virtualization container technology, Docker is widely used in today's automated operations, along with the major cloud platforms AWS, Aliyun, and the container orchestration engine kubernetes are also based on Docker as a basic unit of service. So the first step in deploying an application is to create an application image, that is, to write dockerfile, such as
CMD "Java-jar App.jar"
The basic process is:
- Based on a base image, such as Java:alpine
- Build a project to generate a product, such as a JRE
- The portal that defines the image is entrypoint or cmd, "Java-jar xx.jre"
In the actual project, the Dockerfile is far from simple, for example, the underlying image provided by OPENJDK may not have the environmental dependencies we need, such as the need for gradle support when building a Java project, such as a dependency package that is posted on GitHub, We need a git command, or we need to use Gitcrypt to decrypt some sensitive environment variables when we run the mirror, which means that we need to make some modifications based on the underlying image, such as: Run apk add git when the project environment relies on more and more, We'll find that the ever-bloated Docker image can seriously slow down the construction time of the project, and each time our CI/CD server is deployed it will download a lot of dependencies.A best practice is to create its own base image for the project, meaning that the next build uses the underlying image that was built directly. So where do we put the base image we're building?
If you've heard of the Docker hub for the first time, you can understand that the software industry has two of the largest public repositories, one for code, GitHub, and one for Docker mirroring, called Dockerhub.
Docker Hub is the world's largest public repository of Docker images, where a large number of Docker developers, open source projects, and independent software vendors (ISVs) build and distribute their mirrors.Docker Hub is also the official Docker repository, when r unning the command Docker pull Alpine is the Alpine image pulled from the Docker hub. We can pull and upload our images free of charge from the Docker hub, and we can use the Docker hub if we have enough money. In the real project development of the geek, I haven't used the Docker hub's properties, on the one hand, it is extremely cheap and convenient to use the AWS Image warehouse.
In general, I will use the Docker Hub,
- Docker your own open source project for easy demonstration
When you open up your project on GitHub, is there a presentation related to the first impression of the project, using Docker to build open source projects locally, such as @geekeren/magpie, which is stored at the Docker Hub, is quick and easy, regardless of the environment, you just The Docker run-p 80:80 Bywang/magpie can be easily demonstrated.
- Store the base image of the team project
The underlying image image is not an application image, it does not contain our project code, it is easy to reuse our Docker images by ourselves or others, and can contribute to the community.
- Reduce CI pressure and speed up construction the low-frequency of the change of environment dependent changes our base image does not need to be updated frequently or frequently, and the underlying image is stored on the Docker hub and the process of building the underlying image is stripped from the CI.
Automated construction of the Docker hub
The Docker hub Automation build allows us to correlate GitHub, BitBucket projects and automatically build mirrors based on specified dockerfile, while Webhook notification update mechanism enables Docker to be triggered when dockerfile on GitHub is updated Hub is built to ensure that the image is the latest version.
Here's how you can use Docker hub automation to build
- 1. Click "Create" in the navigation bar to select "Automated Build"
- 2. Associate a GitHub account, which may require you to log in to your GitHub account
- 3. Select a GitHub dockerfile project here I am using a Docker project that integrates Git-crypt in Gradle: Https://github.com/geekeren/docker-gradle-gitcrypt
At this time a Docker Hub repo has been gaocheng, and we can use it in the application image of the project:
This article has been in the copyright printing record, protected by copyright law, without permission shall not be reproduced!If you think this article is useful for you, you can click on the "sponsor author" below to hit the author!
Reprint Annotated Original source:Baiyuan's Blog> >https://wangbaiyuan.cn/en/using-dockerhub-continually-build-container-mirroring-2.html