1. Question: When we actually develop, the database is deployed on the intranet, and when our program connects to the database, we need to specify the intranet address. But sometimes we need to migrate the environment, so our backend code has to be modified accordingly. Is there a good way to prevent us from modifying the code? Answer: It is certain that there is, and that is, what is specified in the code is not the IP address, but the domain name. We only need to configure the domain name and IP address to establish a mapping relationship, and all projects can achieve the goal without changing the code. 2. Question: The official environment is usually in the form of a cluster, with at least three servers. Do we need to buy three domain names? Moreover, the domain name can only be bound to the public IP. Can we make the database public to the external network? For security reasons, no one will open the database to the external network. What should we do then? Answer: That is to modify the host file and customize our domain name and the intranet IP of the database cluster in the host. On a physical Linux machine, simply modify the /etc/host file. If our service is deployed on Linux in the form of docker. So how do you modify the host in docker? 1. Command Generally, the images of the formal environment are compiled in advance. If the image is not compiled by docker-compose, it is difficult to modify the host, so we can only configure it through parameters at startup. docker run --add-host=www.scalerwang.com:192.168.1.100 --add-host=blog.scalerwang.com:192.168.1.200 --name wangscaler -it mydocker Use command parameters to specify --add-host 2. docker-compose.ymlSpecify in yml that the compiled docker container automatically configures the host file. The yaml related content is as follows services: service-nginx: image: nginx extra_hosts: - "www.scalerwang.com:192.168.1.100" - "blog.scalerwang.com:192.168.1.200" 3. Dockerfile Dockerfile does not have direct parameters to modify the host file directly. If you want to modify the host file through Dockerfile, you need to prepare the host file in advance and put it in the root directory of your code. MAINTAINER [email protected] ADD //wangscaler RUN cat /wangscaler/hosts >> /etc/hosts This is also possible. 4. Direct modification If you don't mind the effort, you can try it. Of course, if your program is started in the background and cannot be started due to the wrong environment, you cannot go in and modify it. 5. Modify the image If your project is deployed in the form of docker, it is often compiled into an image through dockerfile and docker-compose first. At this time, you can pull down the image, modify the host, and then push it up again to overwrite the original image. Summarize The best methods are the first two, which save time and effort and can be done in one go. If you are compiling an image with dockerfile, choose the first option; if you are compiling with docker-compose, just modify docker-compose.yml once and for all. The third one is also acceptable, but for the last two, just pretend you don’t know and don’t try to do them. This is the end of this article about how to customize the host file in Docker. For more information about customizing the host file in Docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of the idea of achieving the point-earning effect with CSS animation
>>: In-depth analysis of the role of HTML <!--...--> comment tags
When you use HTML div blocks and the middle of th...
Visual Studio Code is a powerful text editor prod...
Preface The previous article installed Hadoop, an...
Table of contents 1. Installation 2.APi 3. react-...
Ⅰ. Problem description: Use html+css to implement...
mysql 8.0.22 winx64 installation and configuratio...
Locks in MySQL Locks are a means to resolve resou...
In order to make the table fill the screen (the re...
As a tester, you may often need to install some s...
The function to be implemented today is the follo...
[mysql] replace usage (replace part of the conten...
Dimensionality reduction of two-dimensional array...
Preface This article introduces a simple BAT scri...
Table of contents Variable Scope The concept of c...
Many people use Linux Homebrew. Here are three ti...