Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add docker support #6715

Merged
merged 1 commit into from
Jan 12, 2022
Merged
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
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
venv
venv**
.github
.pytest**
doc
experiment
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
51 changes: 51 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,57 @@ We have written guides on how to package Tribler for distribution on various sys
* `Windows <http://tribler.readthedocs.io/en/latest/building/building_on_windows.html>`_
* `macOS <http://tribler.readthedocs.io/en/latest/building/building_on_osx.html>`_


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!
=============

Expand Down
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

3 changes: 1 addition & 2 deletions src/run_tribler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 '')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down