maven build and pit push image encountered (the learning process of recording)

Recently doing continuous integration build jenkins, one of which is to achieve the docker container deployment. The project itself is a maven project, I am maven and docker have no cognitive basis, and thus help Baidu official website, starting from scratch bite. I met a lot of the pit, but fortunately did not give up, little by little to fill up, where the learning process simply record it.

What is maven?

I read a lot of explanation, much the same, but if you do not have contact with, will feel abstract and incomprehensible. Or to explain the official website of the translation, after all, this is the most authoritative. Maven, a Yiddish word meaning the accumulation of knowledge, originally used to simplify the process of building in Jakata Turbine project. There were some projects (have their own Ant build file), just slightly different, and JAR files by CVS to maintain. So we hope to have a standardized way to build the project, consisting of a clear way to define the project, an easy way to publish information about the project, as well as a simple way to share JARs across multiple projects. Any resulting on a tool can now be used to build and manage a java project.

Simply put, Maven is a tool for managing java projects in many dependent jar package, thereby simplifying the build and release java project. The most important is that in the maven pom.xml file, the full name of the project object model (Project Object Model), which is used to describe specific projects. maven life cycle is invoked when running mvn install, then maven perform a series of sequential steps to run a number of default plugin goals which completed its work like compile and create a jar file.

Seen in this light, maven is not mysterious and complex, frequently used commands so few. Many times maven project and docker used together, together as a container released.

What is a docker?

docker can be said of today's most popular IT industry concept. Businesses are in a container deployment target, it is easy to use, efficient, lightweight and reliable. References Baidu Wikipedia definition: Docker is an open source application container engine, allowing developers to package their applications and dependencies to mirror a transplant, then publish to any of the popular  Linux or on a Windows machine, you can achieve a virtual of . The container is full use of the sandbox mechanism will not have any interface with each other.

docker commonly used commands I used are the following:

View the existing docker mirror

This is very easy to use, it can be confirmed whether the mirror to generate success.

Remove Mirror

docker rmi image_name

Use dockerfile packaged mirror

docker build --no-cache -t image_repository:imageTag .

no-cache said they did not use to create mirrored cache, -t represents the mirror image of the name and label, pay attention to the final. must be, otherwise it will error

push mirror

# Make a good docker image pushed to specify the harbor warehouse
docker push image_repository:dockerTag

docker Login

docker login -u harbor_username --password harbor_pwd harbor_ip

Restart docker daemon

systemctl daemon-reload

Restart docker Service

systemctl restart docker

Note that each time docker configuration information changes, you need to refresh, it is to restart the daemon docker or docker service.

Knowledge combing is completed, talk about the pit packed encountered:

1. Use mvn build and mvn push mirroring and docker's build and push What is the difference?

Both methods I have tried it, compared to feel there is no difference, mvn package command and seemingly also called push and push package docker, of course, the premise is that you want to install the maven plugin docker, otherwise it will error, like this

In this case, can be directly used to build and docker push command, and the same image can be generated pushed successfully warehouse.

2. When push mirroring, port number 443 error prompt connection refused

Baidu online for a long time, virtually no usable solutions, has said that the server is not listening port, causing the connection is rejected by netstat -an | grep 443 after the inquiry found that not also have said that the listening port of the other ip occupation, such as 127.0.0.1, also found that not. Finally only to see the official website https://docs.docker.com/config/daemon/systemd/ , here referred to the daemon configuration docker, the main recommendation is to use daemon.json in the / etc / docker / path file to configure, open the file and found that there are an insecure-registries, online search a bit, dockerfile image uploaded must https way through, so there needs to be uploaded to the warehouse address written inside this one.

Docker need to restart the service after the entry into force settings finished.

3. When push mirrored, error prompt unauthorized: authentication required

The same is prompted, the official website of this is due to the https proxy environment variable is not added, the method according to the official website, to create this file

sudo  mkdir -p /etc/systemd/system/docker.service.d

Then add the https proxy configuration file

touch /etc/systemd/system/docker.service.d/https-proxy.conf

Add the following environmental information

[Service]
Environment="HTTPS_PROXY=https://proxy.example.com:443/"

Finally, restart the daemon and docker docker services

$ sudo systemctl daemon-reload

$ sudo systemctl restart docker

Get! Finally ushered in the hope of picture

This experience is very valuable, from ignorance to understanding, just need to make unremitting efforts only. In 300 software tested advice (do not remember the specific name, a very good book), to mention a very complex concept, do not be scared, a little bit familiar with it, so you slowly become more proficient, you will have new ideas, new knowledge, new understanding. This is an ongoing process and close, like agility, no one has the perspective of God, we can only do a constantly upgrade their knowledge of ordinary people.

 

Guess you like

Origin www.cnblogs.com/jingmu/p/11008750.html