Skip to content

Latest commit

 

History

History

desktop

docker-connector

Accept connection from desktop-connector in docker, and route container's ip to it. Also can expose the access capabilities of Docker containers to others who use docker-accessor

Install

You can install from brew

$ brew install wenjunxiao/brew/docker-connector

Or download the latest version directly from release

# change the version to latest version
$ curl -sSL -o- https://github.com/wenjunxiao/mac-docker-connector/releases/download/v1.0/docker-connector-mac.tar.gz | tar -zxf - -C /usr/local/bin/

Usage

If install by brew, just start as a service.

$ sudo brew services start docker-connector

Add routes which container subnets you want to access for the first time, and you can add or delete later. You can add all bridge subnet by docker network ls --filter driver=bridge

$ docker network ls --filter driver=bridge --format "{{.ID}}" | xargs docker network inspect --format "route {{range .IPAM.Config}}{{.Subnet}}{{end}}" >> "$(brew --prefix)/etc/docker-connector.conf"

Or just add specified subnet route you like

$ cat <<EOF >> "$(brew --prefix)/etc/docker-connector.conf"
route 172.100.0.0/16
EOF

Start with the specified configuration file

$ sudo ls # cache sudo password
$ nohup sudo ./docker-connector -config "$(brew --prefix)/etc/docker-connector.conf" &

Expose access

You can expose the containers to others, so that they can access the network you built in docker. Add expose listen address and access tokens.

$ cat <<EOF >> "$(brew --prefix)/etc/docker-connector.conf"
expose 0.0.0.0:2512
token user1 192.168.251.3
token user2 192.168.251.4
EOF

And append expose the route which you want to expose to others.

route 172.100.0.0/16 expose

For test, you can turn on pong to intercept ping requests(only IPv4)

$ cat <<EOF >> "$(brew --prefix)/etc/docker-connector.conf"
pong on
EOF

Hosts

A simple DNS server for docker containers, which use the hosts file and filtered by domain suffix, such as .local

hosts /etc/hosts .local .local1

It will usefull for a domain with ip 127.0.0.1, which will be resolved as another avaliable ip for container, such as 192.168.251.2. So, you can use any custom domain (/etc/hosts for Mac or C:\Windows\System32\drivers\etc\hosts for Windows) both in host and conatiner,

127.0.0.1 api.example.local

You can use comment to force ignore (docker-connector:ignore) or include (docker-connector:resolve) the entry.

127.0.0.1 ignore.example.local # docker-connector:ignore
127.0.0.1 api.example.resolve # docker-connector:resolve

Proxy

A simple proxy server for a tcp service with host 127.0.0.1. It will be usefull for a service, which is only accessible by the host and the container

proxy 127.0.0.1:80:80

The first part host:port is the service listening, and the last port 80 is the proxy listening.

Compile

$ go env -w GOPROXY=https://goproxy.cn,direct
$ go build -tags netgo -o docker-connector .

Publish

Publish this to Homebrew for easy installation.

Release

Build and make a tarball for Mac

$ go build -tags netgo -o ./build/darwin/docker-connector .
$ tar -czf build/docker-connector-darwin.tar.gz -C ./build/darwin docker-connector
$ shasum -a 256 build/docker-connector-darwin.tar.gz | awk '{print $1}' > build/docker-connector-darwin-sha256.txt

Build and make a zip for Windows

$ GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -tags netgo -o ./build/win/x86_64/docker-connector/docker-connector.exe .
$ cat options.conf.template > ./build/win/x86_64/docker-connector/options.conf.sample
$ cp tools/* ./build/win/x86_64/docker-connector/
$ cd ./build/win/x86_64/ && zip -r docker-connector-win-x86_64.zip docker-connector && cd ../../../
$ GOOS=windows GOARCH=386 go build -ldflags "-s -w" -tags netgo -o ./build/win/i386/docker-connector/docker-connector.exe .
$ cat options.conf.template > ./build/win/i386/docker-connector/options.conf.sample
$ cp tools/* ./build/win/i386/docker-connector/
$ cd ./build/win/i386/ && zip -r docker-connector-win-i386.zip docker-connector && cd ../../../

Upload the tarball to Releases

Homebrew

Create a ruby repository named homebrew-brew, which must start with homebrew-. Clone it and add formula named docker-connector.rb in Formula

$ git clone https://github.com/wenjunxiao/homebrew-brew
$ cd homebrew-brew
$ mkdir Formula && cd Formula
$ cat <<EOF > docker-connector.rb
class DockerConnector < Formula
  url https://github.com/wenjunxiao/mac-docker-connector/releases/download/x.x.x/docker-connector-mac.tar.gz
  sha256 ...
  version ...
  def install
    bin.install "docker-connector"
  end
  def plist
    <<~EOS
      ...
    EOS
  end
end
EOF
$ cd ../
$ git add . && git commit -m "..."
$ git push origin master

You can install by brew.

$ brew install wenjunxiao/brew/docker-connector

In addition to github, it can be stored in other warehouses, and other protocols can also be used. Such as gitee.com. You need to specify the full path when installing

$ brew tap wenjunxiao/brew https://gitee.com/wenjunxiao/homebrew-brew
$ brew install docker-connector

If it has already been tapped, you can change remote

$ cd `brew --repo`/Library/Taps/wenjunxiao/homebrew-brew
$ git remote set-url origin https://gitee.com/wenjunxiao/homebrew-brew.git
$ brew install docker-connector

Dev

Run main.go without default config in debug mode.

$ sudo go run main.go -port 2521 -addr 192.168.252.1/24 -cli false

References