Solve the problem that some configuration files in /etc are reset after the docker container is restarted

Solve the problem that some configuration files in /etc are reset after the docker container is restarted

1.

The three files /etc/hosts, /etc/resolv.conf and /etc/hostname in the container do not exist in the image, but exist in /var/lib/docker/containers/. When starting the container, these files are mounted into the container in the form of mount.

Therefore, if these files are modified in the container, the modified parts will not exist in the top layer of the container, but will be written directly to these three physical files.

2. Why does the modified content disappear after restart?

The reason is: every time Docker starts a container, it rebuilds a new /etc/hosts file. Why is this?

The reason is: the container is restarted, the IP address is changed, and the original IP address in the hosts file is invalid. Therefore, the hosts file should be modified, otherwise dirty data will be generated.

3. Is there any good solution?

You can use the --add-host parameter of the docker run command to add a mapping between host and ip for the container.

Supplement: Solve the problem that the restart configuration does not take effect in the Docker container (source /etc/profile)

Problem description:

When using Docker, you may need to customize some configuration files in the container instance, such as /etc/profile. However, after the modification, you need to manually source it every time you start the container to make it effective again, which is very cumbersome.

Solution:

In the container instance, add source /etc/profile to the end of the ~/.bashrc configuration file, save the file and exit. This will allow the configuration file to be automatically refreshed after restart without manual operation.

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • How to solve the Docker container startup failure
  • Solution to the failure of entering the container due to full docker space
  • Docker View the Mount Directory Operation of the Container
  • docker run -v mounts data volumes abnormally, and the container status is always restarting

<<:  Example code for implementing image adaptive container with CSS

>>:  Web page creation basic declaration document type description (DTD

Recommend

Introduction to document.activeELement focus element in JavaScript

Table of contents 1. The default focus is on the ...

Docker View the Mount Directory Operation of the Container

Only display Docker container mount directory inf...

WeChat applet uses the video player video component

This article example shares the specific code of ...

Detailed explanation of MySQL covering index

concept If the index contains all the data that m...

Summary of knowledge points about events module in Node.js

Through the study and application of Node, we kno...

Vue virtual Dom to real Dom conversion

There is another tree structure Javascript object...

Introduction to the B-Tree Insertion Process

In the previous article https://www.jb51.net/arti...

HTML table tag tutorial (25): vertical alignment attribute VALIGN

In the vertical direction, you can set the row al...

Some ways to eliminate duplicate rows in MySQL

SQL statement /* Some methods of eliminating dupl...

Diving into JS inheritance

Table of contents Preface Prepare Summarize n way...

The basic use of html includes links, style sheets, span and div, etc.

1. Links Hypertext links are very important in HTM...

JavaScript to achieve click image flip effect

I was recently working on a project about face co...

MySQL compression usage scenarios and solutions

Introduction Describes the use cases and solution...

Implementation of Docker data volume operations

Getting Started with Data Volumes In the previous...