-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,22 @@ | ||
# docker-local-hosts | ||
Update your local hosts file with internal IP addresses of Docker containers | ||
Docker /etc/hosts sync | ||
====================== | ||
|
||
Simple CLI tool for updating your local /etc/hosts file with a .local pointer to a Docker container's internal IP address. | ||
|
||
Use Case | ||
-------- | ||
|
||
Say you're developing a Nodejs app, and you want to run that inside a Docker container during development, but access it from your desktop browser. | ||
|
||
You could publish the container port to a well known port, but that might cause conflicts with other services, and isn't great in terms of isolation. The other option is to inspect the container's internal IP address and use that, but if you want to reference this container in another project, that's going to become tedios. | ||
|
||
`docker-local-hosts` solves that problem by inspecting the container, grabbing it's IP address, and safely updating your /etc/hosts file with a .local based pointer. You can run this inside your Makefile to sync the container address each time you create the container, for example, as part of docker compose. | ||
|
||
Usage | ||
----- | ||
|
||
`docker-local-hosts map -c <container_name> -l </etc/hosts name>` | ||
|
||
This will create an entry in your `/etc/hosts` file that points the internal IP address of the container to a hostname you provided with `.local` appended to it. | ||
|
||
You can now access that container from your desktop using the `.local` hostname. |