Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Create a Dockerfile for Hysteria client, with wiki in the README #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions docker/hysteria/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ It can be found at [Docker Hub][4].

You **must create a configuration file** `/etc/hysteria/server.yaml` in host at first:

```
```bash
$ mkdir -p /etc/hysteria
```

A sample in yaml like below:

```
```yaml
listen: :8998

tls:
Expand All @@ -56,6 +56,60 @@ There is an example to start a container that listen on port `8998`, run as a Hy
$ docker run -d -p 8998:8998 --name hysteria --restart=always -v /etc/hysteria:/etc/hysteria teddysun/hysteria
```

## Start a container as Hysteria client with socks proxy

## Pull the image

```bash
$ docker pull teddysun/hysteria-client
```

You **must create a configuration file** `/etc/hysteria/client.yaml` in host at first:

```bash
$ mkdir -p /etc/hysteria
```

A sample in yaml like below:

```yaml
server: "IP:8998"
# server: "IP:8998,10000-20000" port hopping is availiable

auth: your_password

tls:
sni: www.example.com
# sni: www.bing.com
insecure: true

#need expose socks proxy server port
socks5:
listen: 0.0.0.0:1080
disableUDP: false

transport:
udp:
hopInterval: 30s

#optional
#lazy: true
#bandwidth:
#up: 150 mbps
#down: 150 mbps
# quic:
# initStreamReceiveWindow: 16777216
# maxStreamReceiveWindow: 16777216
# initConnReceiveWindow: 33554432
# maxConnReceiveWindow: 33554432
```
There is an example to start a container that listen on port `1080`, run as a Hysteria client like below:

```bash
$ docker run -d -p 1080:1080 --name hysteria-client --restart=always -v /etc/hysteria:/etc/hysteria teddysun/hysteria-client
```
Then access socks server with `client_hostIP:1080`

**Warning**: The port number must be same as configuration and opened in firewall.

[1]: https://github.com/apernet/hysteria
Expand Down
21 changes: 21 additions & 0 deletions docker/hysteria/client/Dockerfile.architecture
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Dockerfile for hysteria client based alpine
# Copyright (C) 2023 Teddysun <i@teddysun.com>
# Reference URL:
# https://github.com/HyNetwork/hysteria

FROM --platform=${TARGETPLATFORM} alpine:latest
LABEL maintainer="Teddysun <i@teddysun.com>"

ARG TARGETPLATFORM
WORKDIR /root
COPY hysteria.sh /root/hysteria.sh
COPY client.yaml /etc/hysteria/client.yaml
RUN set -ex \
&& apk add --no-cache bash tzdata ca-certificates \
&& chmod +x /root/hysteria.sh \
&& /root/hysteria.sh "${TARGETPLATFORM}" \
&& rm -fv /root/hysteria.sh

VOLUME /etc/hysteria
ENV TZ=Asia/Shanghai
CMD [ "/usr/bin/hysteria", "client", "-c", "/etc/hysteria/client.yaml" ]
55 changes: 55 additions & 0 deletions docker/hysteria/client/build_hysteria.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/sh
#
# This is a Shell script for build multi-architectures hysteria binary file
#
# Supported architectures: amd64, arm32v6, arm32v7, arm64v8, i386, ppc64le, s390x
#
# Copyright (C) 2022 - 2023 Teddysun <i@teddysun.com>
#
# Reference URL:
# https://github.com/apernet/hysteria

cur_dir="$(pwd)"

COMMANDS=( git go )
for CMD in "${COMMANDS[@]}"; do
if [ ! "$(command -v "${CMD}")" ]; then
echo "${CMD} is not installed, please install it and try again" && exit 1
fi
done

cd ${cur_dir}
echo "git clone https://github.com/apernet/hysteria.git"
git clone https://github.com/apernet/hysteria.git
cd hysteria || exit 2

APP_SRC_CMD_PKG="github.com/apernet/hysteria/app/cmd"
VERSION="$(git describe)"
COMMIT="$(git rev-parse HEAD)"
TIMESTAMP="$(date "+%F")"

LDFLAGS="-s -w -X '${APP_SRC_CMD_PKG}.appVersion=${VERSION}' -X '${APP_SRC_CMD_PKG}.appCommit=${COMMIT}' -X '${APP_SRC_CMD_PKG}.appDate=${TIMESTAMP}' -X '${APP_SRC_CMD_PKG}.appType=release' -buildid="
ARCHS=( 386 amd64 arm arm64 ppc64le s390x )
ARMS=( 6 7 )

for ARCH in ${ARCHS[@]}; do
if [ "${ARCH}" = "arm" ]; then
for V in ${ARMS[@]}; do
echo "Building hysteria_linux_${ARCH}${V}"
env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GOARM=${V} go build -v -trimpath -ldflags "${LDFLAGS} -X '${APP_SRC_CMD_PKG}.appPlatform=linux' -X '${APP_SRC_CMD_PKG}.appArch=${ARCH}'" -o ${cur_dir}/hysteria_linux_${ARCH}${V} ./app || exit 1
done
else
echo "Building hysteria_linux_${ARCH}"
env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -v -trimpath -ldflags "${LDFLAGS} -X '${APP_SRC_CMD_PKG}.appPlatform=linux' -X '${APP_SRC_CMD_PKG}.appArch=${ARCH}'" -o ${cur_dir}/hysteria_linux_${ARCH} ./app || exit 1
fi
done

ARCHS=( 386 amd64 )
for ARCH in ${ARCHS[@]}; do
echo "Building hysteria_windows_${ARCH}.exe"
env CGO_ENABLED=0 GOOS=windows GOARCH=${ARCH} go build -v -trimpath -ldflags "${LDFLAGS} -X '${APP_SRC_CMD_PKG}.appPlatform=windows' -X '${APP_SRC_CMD_PKG}.appArch=${ARCH}'" -o ${cur_dir}/hysteria_windows_${ARCH}.exe ./app
done

chmod +x ${cur_dir}/hysteria_*
# clean up
cd ${cur_dir} && rm -fr hysteria
File renamed without changes.
51 changes: 51 additions & 0 deletions docker/hysteria/client/hysteria.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh
#
# This is a Shell script for hysteria based alpine with Docker image
#
# Copyright (C) 2022 Teddysun <i@teddysun.com>
#
# Reference URL:
# https://github.com/HyNetwork/hysteria

PLATFORM=$1
if [ -z "$PLATFORM" ]; then
ARCH="amd64"
else
case "$PLATFORM" in
linux/386)
ARCH="386"
;;
linux/amd64)
ARCH="amd64"
;;
linux/arm/v6)
ARCH="arm6"
;;
linux/arm/v7)
ARCH="arm7"
;;
linux/arm64|linux/arm64/v8)
ARCH="arm64"
;;
linux/ppc64le)
ARCH="ppc64le"
;;
linux/s390x)
ARCH="s390x"
;;
*)
ARCH=""
;;
esac
fi
[ -z "${ARCH}" ] && echo "Error: Not supported OS Architecture" && exit 1
# Download binary file
HYSTERIA_FILE="hysteria_linux_${ARCH}"

echo "Downloading binary file: ${HYSTERIA_FILE}"
wget -O /usr/bin/hysteria https://dl.lamp.sh/files/${HYSTERIA_FILE} > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: Failed to download binary file: ${HYSTERIA_FILE}" && exit 1
fi
echo "Download binary file: ${HYSTERIA_FILE} completed"
chmod +x /usr/bin/hysteria