Extend hoster to get paths from environment.
This commit is contained in:
parent
581f5c1e66
commit
7942a16cd6
|
|
@ -1,4 +1,4 @@
|
||||||
FROM frolvlad/alpine-python3
|
FROM python:3.10.6-alpine3.16
|
||||||
|
|
||||||
RUN pip3 install docker
|
RUN pip3 install docker
|
||||||
RUN mkdir /hoster
|
RUN mkdir /hoster
|
||||||
|
|
@ -6,6 +6,3 @@ WORKDIR /hoster
|
||||||
ADD hoster.py /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
|
# Hoster
|
||||||
|
|
||||||
|
## Mount hosts file directyly
|
||||||
A simple "etc/hosts" file injection tool to resolve names of local Docker containers on the host.
|
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:
|
hoster is intended to run in a Docker container:
|
||||||
|
|
||||||
docker run -d \
|
docker run -d \
|
||||||
-v /var/run/docker.sock:/tmp/docker.sock \
|
--mount type=bind,source=/var/run/docker.sock,target=/tmp/docker.sock \
|
||||||
-v /etc/hosts:/tmp/hosts \
|
--mount type=bind,source=/etc/hosts,target=/tmp/hosts \
|
||||||
dvdarias/docker-hoster
|
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.
|
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.
|
Hoster inserts into the host's `/etc/hosts` file an entry per running container and keeps the file updated with any started/stoped container.
|
||||||
|
|
|
||||||
|
|
@ -129,9 +129,11 @@ def update_hosts_file():
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
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 = 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('socket', type=str, nargs="?", default=sockPath, 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('file', type=str, nargs="?", default=hostPath, help='The /etc/hosts file to sync the containers with.')
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue