diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000000..4958bd30f9e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +venv +venv** +.github +.pytest** +doc +experiment \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..9372ed2606c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +# The base image already builds the libtorrent dependency so only Python pip packages +# are necessary to be installed to run Tribler core process. +FROM triblercore/libtorrent:1.2.10-x + +# Update the base system and install required libsodium and Python pip +RUN apt update && apt upgrade -y +RUN apt install -y libsodium23 python3-pip git + +# Then, install pip dependencies so that it can be cached and does not +# need to be built every time the source code changes. +# This reduces the docker build time. +RUN mkdir /requirements +COPY ./src/pyipv8/requirements.txt /requirements/pyipv8-requirements.txt +RUN pip3 install -r /requirements/pyipv8-requirements.txt + +COPY ./src/tribler-common/tribler_common/requirements.txt /requirements/common-requirements.txt +RUN pip3 install -r /requirements/common-requirements.txt + +COPY ./src/tribler-core/tribler_core/requirements.txt /requirements/core-requirements.txt +RUN pip3 install -r /requirements/core-requirements.txt + +# Copy the source code and set the working directory +COPY ./ /tribler +WORKDIR /tribler + +# Set the REST API port and expose it +ENV CORE_API_PORT=52194 +EXPOSE 52194 + +# Only run the core process with --core switch +CMD ["./src/tribler.sh", "--core"] diff --git a/README.rst b/README.rst index c6536a31ab0..86f6946398a 100644 --- a/README.rst +++ b/README.rst @@ -56,6 +56,57 @@ We have written guides on how to package Tribler for distribution on various sys * `Windows `_ * `macOS `_ + +Docker support +================= + +Dockerfile is provided with the source code which can be used to build the docker image. + +To build the docker image: + +.. code-block:: bash + + docker build -t triblercore/triblercore:latest . + + +To run the built docker image: + +.. code-block:: bash + + docker run -p 52194:52194 --net="host" triblercore/triblercore:latest + +Note that by default, the REST API is bound to localhost inside the container so to +access the APIs, network needs to be set to host (--net="host"). + +The REST APIs are now accessible at: http://localhost:52194/docs + + +**Docker Compose** + +Tribler core can also be started using Docker Compose. For that, a `docker-compose.yml` file is available +on the project root directory. + +To run via docker compose: + +.. code-block:: bash + + docker-compose up + + +To run in detached mode: + +.. code-block:: bash + + docker-compose up -d + + +To stop Tribler: + +.. code-block:: bash + + docker-compose down + + Get in touch! ============= diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000000..e3096228833 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3.3" + +services: + tribler-core: + image: triblercore/triblercore:latest + container_name: triblercore + network_mode: "host" + build: . + environment: + CORE_API_PORT: 52194 + diff --git a/src/run_tribler.py b/src/run_tribler.py index f74090144d4..bdaf61421f5 100644 --- a/src/run_tribler.py +++ b/src/run_tribler.py @@ -6,8 +6,6 @@ import os import sys -from PyQt5.QtCore import QSettings - from tribler_common.logger import load_logger_config from tribler_common.process_checker import ProcessChecker from tribler_common.sentry_reporter.sentry_reporter import SentryStrategy @@ -100,6 +98,7 @@ def init_boot_logger(): process_checker.remove_lock_file() else: + from PyQt5.QtCore import QSettings from tribler_gui.utilities import get_translator logger.info('Running GUI' + ' in gui_test_mode' if parsed_args.gui_test_mode else '') diff --git a/src/tribler-core/tribler_core/components/restapi/rest/rest_manager.py b/src/tribler-core/tribler_core/components/restapi/rest/rest_manager.py index 29639565525..a5c99e64421 100644 --- a/src/tribler-core/tribler_core/components/restapi/rest/rest_manager.py +++ b/src/tribler-core/tribler_core/components/restapi/rest/rest_manager.py @@ -82,6 +82,9 @@ def __init__(self, config: APISettings, root_endpoint: RootEndpoint, state_dir=N self.config = config self.state_dir = state_dir + self.http_host = '127.0.0.1' + self.https_host = '0.0.0.0' + def get_endpoint(self, name): return self.root_endpoint.endpoints.get('/' + name) @@ -122,13 +125,13 @@ async def start(self): if self.config.http_enabled: api_port = self.config.http_port if not self.config.retry_port: - self.site = web.TCPSite(self.runner, 'localhost', api_port) + self.site = web.TCPSite(self.runner, self.http_host, api_port) await self.site.start() else: bind_attempts = 0 while bind_attempts < 10: try: - self.site = web.TCPSite(self.runner, 'localhost', api_port + bind_attempts) + self.site = web.TCPSite(self.runner, self.http_host, api_port + bind_attempts) await self.site.start() self.config.http_port = api_port + bind_attempts break @@ -144,7 +147,7 @@ async def start(self): ssl_context.load_cert_chain(cert) port = self.config.https_port - self.site_https = web.TCPSite(self.runner, '0.0.0.0', port, ssl_context=ssl_context) + self.site_https = web.TCPSite(self.runner, self.https_host, port, ssl_context=ssl_context) await self.site_https.start() self._logger.info("Started HTTPS REST API: %s", self.site_https.name)