Comments (7)
I'm reading a bit about the way you can get docker
and docker-compose
container IPs. Maybe we can do a simple version that just read from docker and sync a profile with docker IPs.
The command I'm using to test is this:
docker ps -q | xargs docker inspect --format \
'{{ range .NetworkSettings.Networks }}{{ .IPAddress }} {{ $.Name }}{{ println }}{{ end }}'
# Output:
172.22.0.6 /worker_1
172.22.0.5 /vote_1
172.21.0.3 /vote_1 # two IPs means it belongs to two networks
172.22.0.3 /db
172.22.0.2 /redis
172.22.0.4 /result_1
172.21.0.2 /result_1
172.17.0.2 /toolkit
From Go is easy to read/parse that info (it can be exported as JSON as well), and setup a profile based from that info. I'll give it a try.
from hostctl.
I was thinking something similar with Kubernetes too. Maybe it can also be applied to docker too.
from hostctl.
Maybe we can create an image which mounts the host file and add the project IPs once it started? I think docker-compose can pass the project name into the container. Question is then, how to handle the project shutdown.
Gonna try to figure out some things now and gonna write my idea here.
from hostctl.
@fabiang this already implemented on v0.7.0
. You can sync with Docker and Docker Compose.
Give it a try and send any feedback. Thanks!
from hostctl.
I've tested it and it works, when I assume that hostctl
is installed on my local system.
What I was trying as well, was to manipulate my hosts file once a project is started or stopped with docker-compose
.
First I made a Dockerfile and an entrypoint script, which you can find here:
https://github.com/fabiang/hostctl/blob/docker-integration/Dockerfile
https://github.com/fabiang/hostctl/blob/docker-integration/docker-entrypoint.sh
I've build the Docker image and added hostsctl as container to two of my projects in the docker-compose.yml
:
version: "2"
services:
# ...
hostctl:
image: guumaster/hostctl
environment:
- PROJECT_NAME=test
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "$HOME/.etchosts:/home/hostctl/.etchosts"
- "/etc/hosts:/etc/host-hosts"
The result in the /etc/hosts is then:
# profile test
172.90.4.4 foo_php_1.loc
172.90.4.2 foo_nginx_1.loc
172.90.4.5 foo_database_1.loc
# end
I can then open http://foo_nginx_1.loc and browse the page.
Of cause there some problems:
- This works only under Linux/Unix, because of the paths are volumes
- The profile isn't removed from /etc/hosts one the project is shut down with
docker-compose stop
To make this automatically work when a project is started or stopped hostctl could do the following:
- Deamonize and scan the network for IP and add them as hosts for each container found on the network. This would allow removing the the mount for
/var/run/docker.sock
- Remove the profile when the daemon receives SIGTERM
- Add a small duration before scanning the network, so the containers are up. Currently I've to run
docker-compose up -d
twice before all IPs are registered.
To override the path to the hosts file and hostctl config for Windows the user must override the settings in docker-compose.yml
in a seconds file and execute docker-compose -f docker-compose.yml -f docker-compose.windows.yml
. Currently there is no other way to archive different mounts per operating system, other then this and an environment variable.
from hostctl.
I just recently added a --wait
flag to do stuff and undo it when receives SIGTERM
signal.
For example:
hostctl sync docker -p awesome --wait 0
It will run until you send ctrl-c
(hence the zero, otherwise it will timeout with a duration flag)
UPDATE: Now is documented and you can read about here Guides > Ephemeral profiles
Let me know if the --wait
flag helps with what you want to do. And also I invite you to check #44 and write a small guide on your use case.
from hostctl.
@fabiang I'm closing this. If you think there is something that can be improved, open a new issue. Thanks!
from hostctl.
Related Issues (20)
- Multiple "DO NOT EDIT" comments in etc/hosts HOT 2
- Display version number as part of --help HOT 4
- fix aur-publish step HOT 9
- hostctl adds entries for the same domain + ip HOT 3
- Comments turn into entries
- Support not etc/hosts config files,such as sysctl.conf and limits.conf HOT 1
- brew install guumaster/tap/hostctl does not work on Apple M1 HOT 7
- v1.1.1 - Access Denied on Windows 10 while running as administrator HOT 2
- i really want to use this by yum or dnf. HOT 1
- runtime error HOT 1
- SegFault - profile.RemoveHostNames - HOT 1
- Windows 11 profiles are not set
- Extremely slow for large files HOT 2
- installation page not found (404) HOT 4
- hostctl removes multi-value domain aliases when adding any domain
- hostctl strips ::0 off ipv6 addresses when adding any domain
- The snap package conflicts with the compiled binary package
- `hostctl sync docker` doesnโt skip containers that do not have an IP address assigned
- GitHub Action
- homebrew ubuntu 22 installation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hostctl.