diff --git a/Dockerfile b/Dockerfile index cddb2206..955ce752 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,17 @@ FROM python:3.10.4-alpine -RUN apk --update --no-cache --no-progress add gcc libffi-dev musl-dev make tor openssl g++ \ - && echo "ControlPort 9051" >> /etc/tor/torrc \ - && echo "CookieAuthentication 1" >> /etc/tor/torrc +RUN apk --update --no-cache --no-progress add gcc libffi-dev musl-dev make openssl g++ WORKDIR /app -VOLUME /app/data COPY . . RUN python3 -m venv venv \ && source venv/bin/activate \ && python3 -m pip install -r requirements.txt -ENV ENABLE_TOR false - -CMD (! ${ENABLE_TOR} || tor&) \ - && source venv/bin/activate \ - && python3 zeronet.py --ui_ip "*" --fileserver_port 26552 +CMD source venv/bin/activate \ + && python3 zeronet.py --ui_ip "*" --fileserver_port 26552 \ + --tor $TOR_ENABLED --tor_controller tor:$TOR_CONTROL_PORT \ + --tor_proxy tor:$TOR_SOCKS_PORT --tor_password $TOR_CONTROL_PASSWD main EXPOSE 43110 26552 diff --git a/Dockerfile.arm64v8 b/Dockerfile.arm64v8 deleted file mode 100644 index d27b7620..00000000 --- a/Dockerfile.arm64v8 +++ /dev/null @@ -1,34 +0,0 @@ -FROM alpine:3.12 - -#Base settings -ENV HOME /root - -COPY requirements.txt /root/requirements.txt - -#Install ZeroNet -RUN apk --update --no-cache --no-progress add python3 python3-dev gcc libffi-dev musl-dev make tor openssl \ - && pip3 install -r /root/requirements.txt \ - && apk del python3-dev gcc libffi-dev musl-dev make \ - && echo "ControlPort 9051" >> /etc/tor/torrc \ - && echo "CookieAuthentication 1" >> /etc/tor/torrc - -RUN python3 -V \ - && python3 -m pip list \ - && tor --version \ - && openssl version - -#Add Zeronet source -COPY . /root -VOLUME /root/data - -#Control if Tor proxy is started -ENV ENABLE_TOR false - -WORKDIR /root - -#Set upstart command -CMD (! ${ENABLE_TOR} || tor&) && python3 zeronet.py --ui_ip 0.0.0.0 --fileserver_port 26552 - -#Expose ports -EXPOSE 43110 26552 - diff --git a/Dockerfile.integrated_tor b/Dockerfile.integrated_tor new file mode 100644 index 00000000..20c4425a --- /dev/null +++ b/Dockerfile.integrated_tor @@ -0,0 +1,18 @@ +FROM python:3.10.4-alpine + +RUN apk --update --no-cache --no-progress add tor gcc libffi-dev musl-dev make openssl g++ \ + && echo "ControlPort 9051" >> /etc/tor/torrc \ + && echo "CookieAuthentication 1" >> /etc/tor/torrc + +WORKDIR /app +COPY . . + +RUN python3 -m venv venv \ + && source venv/bin/activate \ + && python3 -m pip install -r requirements.txt + +CMD (tor&) \ + && source venv/bin/activate \ + && python3 zeronet.py --ui_ip "*" --fileserver_port 26552 + +EXPOSE 43110 26552 diff --git a/Dockerfile.tor b/Dockerfile.tor new file mode 100644 index 00000000..b085747f --- /dev/null +++ b/Dockerfile.tor @@ -0,0 +1,10 @@ +FROM alpine:3.16.0 + +RUN apk --update --no-cache --no-progress add tor + +CMD hashed_control_password=$(tor --quiet --hash-password $TOR_CONTROL_PASSWD) \ + && tor --SocksPort 0.0.0.0:$TOR_SOCKS_PORT \ + --ControlPort 0.0.0.0:$TOR_CONTROL_PORT \ + --HashedControlPassword $hashed_control_password + +EXPOSE $TOR_SOCKS_PORT $TOR_CONTROL_PORT diff --git a/README-ru.md b/README-ru.md index f01c2abe..943ea8d8 100644 --- a/README-ru.md +++ b/README-ru.md @@ -90,6 +90,14 @@ zeronet-conservancy — это форк/продолжение проекта [Z - `source venv/bin/activate` - `python3 zeronet.py` +#### Создание образа Docker +- создание образа: `docker build -t 0net:conservancy . -f Dockerfile` +- или создрание образа с встроенным tor: `docker build -t 0net:conservancy . -f Dockerfile.integrated_tor` +- и его запуск: `docker run --rm -it -v :/app/data -p 43110:43110 -p 26552:26552 0net:conservancy` +- /path/to/0n/data/directory - директория, куда будут сохраняться все данные в том числе секретные ключи. Если вы запускаете в боевом режиме, не потеряйте эту папку! +- или вы можете воспользоваться docker-compose: `docker compose up -d 0net` запускает два контейнера раздельно, для 0net и tor сервисов. +- или: `docker compose up -d 0net-tor` запускает один контейнер с tor и 0net. + #### альтернативный скрипт - после установки общих зависимостей и клонирования репозитория (как указано выше) запустите `start-venv.sh` который создаст для вас виртуальную среду и установит требования Python - больше удобных скриптов будует добавлено в ближайшее время diff --git a/README.md b/README.md index 652cb36d..1c4ea57c 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,14 @@ Install autoconf and other basic development tools, python3 and pip. - `source venv/bin/activate` - `python3 zeronet.py` +#### Build Docker image +- build 0net image: `docker build -t 0net:conservancy . -f Dockerfile` +- or build 0net image with integrated tor: `docker build -t 0net:conservancy . -f Dockerfile.integrated_tor` +- and run it: `docker run --rm -it -v :/app/data -p 43110:43110 -p 26552:26552 0net:conservancy` +- /path/to/0n/data/directory - directory, where all data will be saved, including your secret certificates. If you run it with production mode, do not remove this folder! +- or you can run it with docker-compose: `docker compose up -d 0net` up two containers - 0net and tor separately. +- or: `docker compose up -d 0net-tor` for run 0net and tor in one container. + #### alternative script - after installing general dependencies and cloning repo (as above), run `start-venv.sh` which will create a virtual env for you and install python requirements - more convenience scripts to be added soon diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..5da1fc26 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,51 @@ +version: '3' +services: + tor: + tty: true + stdin_open: true + build: + context: . + dockerfile: Dockerfile.tor + networks: + - 0net-network + ports: + - "9050:9050" + - "9051:9051" + environment: &tor-environments + TOR_CONTROL_PASSWD: some_password + TOR_SOCKS_PORT: 9050 + TOR_CONTROL_PORT: 9051 + 0net: + tty: true + stdin_open: true + build: + context: . + networks: + - 0net-network + volumes: + - 0net-data:/app/data + ports: + - "26552:26552" + - "43110:43110" + depends_on: + - tor + environment: + TOR_ENABLED: enable + <<: *tor-environments + 0net-tor: + tty: true + stdin_open: true + build: + context: . + dockerfile: Dockerfile.integrated_tor + networks: + - 0net-network + volumes: + - 0net-data:/app/data + ports: + - "26552:26552" + - "43110:43110" +volumes: + 0net-data: +networks: + 0net-network: