Merge 7942a16cd6 into 7a5eeb03e8
This commit is contained in:
commit
4f700e3514
|
|
@ -1,11 +1,8 @@
|
|||
FROM frolvlad/alpine-python3
|
||||
FROM python:3.10.6-alpine3.16
|
||||
|
||||
RUN pip3 install docker
|
||||
RUN mkdir /hoster
|
||||
WORKDIR /hoster
|
||||
ADD hoster.py /hoster/
|
||||
|
||||
CMD ["python3", "-u", "hoster.py"]
|
||||
|
||||
|
||||
|
||||
CMD ["python3", "-u", "hoster.py"]
|
||||
15
README.md
15
README.md
|
|
@ -1,14 +1,25 @@
|
|||
# Hoster
|
||||
|
||||
## Mount hosts file directyly
|
||||
A simple "etc/hosts" file injection tool to resolve names of local Docker containers on the host.
|
||||
|
||||
hoster is intended to run in a Docker container:
|
||||
|
||||
docker run -d \
|
||||
-v /var/run/docker.sock:/tmp/docker.sock \
|
||||
-v /etc/hosts:/tmp/hosts \
|
||||
--mount type=bind,source=/var/run/docker.sock,target=/tmp/docker.sock \
|
||||
--mount type=bind,source=/etc/hosts,target=/tmp/hosts \
|
||||
dvdarias/docker-hoster
|
||||
|
||||
## Mount directory containing hosts file
|
||||
In some cases there is a problem while rewriting hosts file. This can be prevent with mapping/mounting complete directory and point to the hosts file with environment variable.
|
||||
|
||||
docker run -d \
|
||||
-e HOST_PATH=/tmp/etc/hosts -e SOCK_PATH=tmp/docker.sock \
|
||||
--mount type=bind,source=/etc,target=/tmp/etc \
|
||||
--mount type=bind,source=/var/run/docker.sock,target=/tmp/docker.sock \
|
||||
dvdarias/docker-hoster
|
||||
|
||||
|
||||
The `docker.sock` is mounted to allow hoster to listen for Docker events and automatically register containers IP.
|
||||
|
||||
Hoster inserts into the host's `/etc/hosts` file an entry per running container and keeps the file updated with any started/stoped container.
|
||||
|
|
|
|||
|
|
@ -136,9 +136,11 @@ def update_hosts_file():
|
|||
|
||||
|
||||
def parse_args():
|
||||
hostPath = os.getenv('HOST_PATH', "/tmp/hosts")
|
||||
sockPath = os.getenv('SOCK_PATH', "tmp/docker.sock")
|
||||
parser = argparse.ArgumentParser(description='Synchronize running docker container IPs with host /etc/hosts file.')
|
||||
parser.add_argument('socket', type=str, nargs="?", default="tmp/docker.sock", help='The docker socket to listen for docker events.')
|
||||
parser.add_argument('file', type=str, nargs="?", default="/tmp/hosts", help='The /etc/hosts file to sync the containers with.')
|
||||
parser.add_argument('socket', type=str, nargs="?", default=sockPath, help='The docker socket to listen for docker events.')
|
||||
parser.add_argument('file', type=str, nargs="?", default=hostPath, help='The /etc/hosts file to sync the containers with.')
|
||||
return parser.parse_args()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Reference in New Issue