Objective
The company has been using the traditional Tomcat to drop the war package architecture system, with the increase of the project, the number of servers, the need to spend a lot of time on different server system environment issues. In order to advance the technology and the operational efficiency of the work, the author introduced the Docker container deployment mode, through the Gitlab+jenkins+harbor system, through the Dockerfile to generate a custom image and place the Harbor warehouse, Jenkins plus custom shell scripts (Implementation of pull image, boot container, container map port pinning, custom log path), etc., basically achieve continuous integration of automated deployment. Test environment in the trial for a period of time, found that the effect is good, but recently found that the application of the container error, according to the error message to locate the Hosts file resolution problem in the container.
Solve
Thus, through a variety of experiments, the solution was found, that is, when the Docker container starts by---add-host way to load the host's resolution into the container, as follows:
/usr/bin/docker run-d \
-P 8,888:7,001 \
-P 9,999:37,001 \
-v/webapps/health_record\.war:/usr/local/tomcat-7001/webapps/health_record\.war \
-v/logs/health_record:/usr/local/tomcat-7001/logs \
-v/logs/hc_logs/health_record:/usr/local/dir_samba \
$ (cat/etc/hosts|awk-f "{if (nr>2) {print"--add-host "$": "$}} ') \
--name Health_record8 \
172.21.97.152/tomcat/tomcat-de:4.0
Description
Focus is the red content, the Hosts file dynamically read, stitching into--add-host to the format, Nr>2 is to filter out the/etc/hosts file in the first two lines (not what I want).
Disadvantages
Hosts files cannot be loaded dynamically, if the Hosts file changes, the container needs to be updated synchronously, the container must be removed to regenerate.
Perfect
This is the way to add parameters when opening the container, or other ways, such as:
1) Enter the container to edit the Hosts file; # Temporary resolution
2) Modify the container default parsing file (that is, the custom Hosts file); # Turn the container into a startup and don't look for/etc/hosts, but instead find the custom Hosts file
Hosts resolution for Docker container loading host