Giter Club home page Giter Club logo

Comments (7)

guumaster avatar guumaster commented on June 7, 2024 2

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.

guumaster avatar guumaster commented on June 7, 2024

I was thinking something similar with Kubernetes too. Maybe it can also be applied to docker too.

from hostctl.

fabiang avatar fabiang commented on June 7, 2024

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.

guumaster avatar guumaster commented on June 7, 2024

@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.

fabiang avatar fabiang commented on June 7, 2024

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:

  1. This works only under Linux/Unix, because of the paths are volumes
  2. 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:

  1. 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
  2. Remove the profile when the daemon receives SIGTERM
  3. 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.

guumaster avatar guumaster commented on June 7, 2024

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.

guumaster avatar guumaster commented on June 7, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.