From 46693f36c1565d7a65150bf9835a1e70bccf5a75 Mon Sep 17 00:00:00 2001 From: Vincent Emonet Date: Mon, 21 Dec 2020 19:39:53 +0100 Subject: [PATCH] Add Dockerfile to build and run LibreTranslate as a Docker image. Also added a docker-compose.yml file to provide a reproducible way to run the Docker image. And finally added how to build and run the Docker image to the README.md. Tested with local deployment on port 5000 and public HTTPS deployment using a docker based nginx-proxy --- Dockerfile | 14 ++++++++++++++ README.md | 22 ++++++++++++++++++++++ docker-compose.yml | 11 +++++++++++ 3 files changed, 47 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1ac2b9b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM python:3.8 + +RUN pip install --upgrade pip + +# Avoid rebuilding this step if no changes to requirements.txt +COPY requirements.txt . +RUN pip install -r requirements.txt + +# Copy everything in the container +# This expects the models submodule to be present +COPY . . + +EXPOSE 5000 +ENTRYPOINT [ "python", "main.py", "--host", "0.0.0.0" ] diff --git a/README.md b/README.md index fc2a8bd..c37f589 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,28 @@ python main.py [args] Then open a web browser to http://localhost:5000 +### Run with Docker + +Make sure you cloned the `models` submodule before building the Docker image: + +```bash +docker build -t libretranslate . +``` + +Run the built image: + +```bash +docker run -it -p 5000:5000 libretranslate [args] +``` + +Or build and run using `docker-compose`: + +```bash +docker-compose up -d --build +``` + +> Feel free to change the [`docker-compose.yml`](https://github.com/uav4geo/LibreTranslate/blob/main/docker-compose.yml) file to adapt it to your deployment needs, or use an extra `docker-compose.prod.yml` file for your deployment configuration. + ## Arguments | Argument | Description | Default | diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..264d23f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3" + +services: + libretranslate: + container_name: libretranslate + build: . + restart: unless-stopped + ports: + - 5000:5000 + ## Uncomment above command and define your args if necessary + # command: --ssl --ga-id MY-GA-ID --req-limit 100 --char-limit 500 \ No newline at end of file