The above docker-compose.yml service will run a basic wordpress container, expose it on port 8080, and add a line in the etc/hosts file that will resolve to the IP address of 127.0.0.1.
This will allow you to add a host entry to a docker container. All you need to do is include the following flag within your docker run command.
#Docker ip address yml how to
How to insert an entry into the hosts file with a docker run commandĭocker has a built in solution that will allow you to have your docker host automatically insert lines into the hosts file of a docker container when the image is initially starting up. Thus, manually editing the file can only be used as a temporary solution. This is because the hosts file is not stored in a persistent volume. You can use the text editor to edit the /etc/hosts file within the container, however, once you rebuild the container, the /etc/hosts file will return to it’s previous state, eliminating your entry. Can’t I just use a text editor to manually edit the host file? An example of when would become necessary is if you are installing WordPress as a Docker container and then receiving the WordPress loopback error when you login to the admin screen. Docker provides an easy way to add a host entry to a docker container. Occasionally when working with a pre-built Docker Container image, it will become necessary for you to add an entry to the /etc/hosts file within the Docker container.
How to insert an entry into the hosts file via Docker Compose.Before and After Examples of the Hosts File.How to insert an entry into the hosts file with a docker run command.Can’t I just use a text editor to manually edit the host file?.