Skip to content

Commit

Permalink
Update README with docker usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jay7x committed Jun 28, 2023
1 parent 54bc029 commit 2ad5d4d
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,62 @@ curl -v -x 127.0.0.1:8080 http://www.example.com

Proxy listens on `127.0.0.1:8080` by default. Use `-L` (or `--listen-address`) CLI option to change this.

## Docker usage

You may use a docker image too if you'd like:

```bash
# Run the proxy in background
docker run -d --name=etc-hosts-proxy -p 8080:8080 --rm \
-e ETC_HOSTS_PROXY_HOSTS_LIST="akamai.com=2.21.250.7,www.akamai.com=2.21.250.7" \
-e ETC_HOSTS_PROXY_DEBUG=true \
ghcr.io/jay7x/etc-hosts-proxy:latest

curl -v -x 127.0.0.1:8080 http://akamai.com

docker logs etc-hosts-proxy
```

NOTE: You should not use 127.0.0.1 (or ::1) as your redirection target in the hosts list while running in a container. This will redirect the request to the container's localhost, which is not what you might expect.

A bit more complex example to redirect some domains to a nginx container:

```bash
# Create a docker network
docker network create somenet

# Run a web server exposed in somenet and on 0.0.0.0:8080 on the host
docker run -d --name=nginx --net=somenet -p 8080:80 --rm nginx:latest

# Run the proxy connected to somenet and exposed on 0.0.0.0:3128 on the host
docker run -d --name=etc-hosts-proxy --net=somenet -p 3128:8080 --rm \
-e ETC_HOSTS_PROXY_HOSTS_LIST="example.com=nginx,www.example.com=nginx" \
-e ETC_HOSTS_PROXY_DEBUG=true \
ghcr.io/jay7x/etc-hosts-proxy:latest

# Check nginx
curl -v http://127.0.0.1:8080

# Check proxy is proxying (note the port is 3128 here)
curl -v -x 127.0.0.1:3128 http://example.com
curl -v -x 127.0.0.1:3128 http://www.example.com
# This should not be redirected
curl -v -x 127.0.0.1:3128 http://example.net

# Check logs
docker logs proxy
docker logs nginx

# Cleanup
docker stop proxy
docker stop nginx
docker network rm somenet
```

Docker images are built by `goreleaser` from the [Dockerfile](https://github.com/jay7x/etc-hosts-proxy/blob/main/.dockerfile)

See [etc-hosts-proxy Github Container registry](https://github.com/jay7x/etc-hosts-proxy/pkgs/container/etc-hosts-proxy) for more details

## Environment variables

| Variable | Description |
Expand Down

0 comments on commit 2ad5d4d

Please sign in to comment.