Hosts resolution for Docker container loading host

Source: Internet
Author: User
Tags docker run

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.