V
V
Vanookay2021-02-11 11:19:51
Docker
Vanookay, 2021-02-11 11:19:51

How to make a service in Docker always on?

Hello, there is a need to make project documentation on a separate port using docker for this. At the moment in the yml file like this:

services:
  nginx:
    restart: always
    build:
      context: .
      dockerfile: docker/local/nginx/Dockerfile
    image: kenguru_local_nginx
    depends_on:
      - django
    ports:
      - 80:80
      - 443:443

  django: &django
    restart: always
    build:
      context: .
      dockerfile: docker/local/django/Dockerfile
    image: kenguru_local_django
    depends_on:
      - postgres
      - mailhog
    volumes:
      - .:/app
    env_file:
      - ./.envs/.local/.django
      - ./.envs/.local/.postgres
    ports:
      - "8000:8000"
    expose:
      - 8000
    command: gunicorn project.wsgi --bind 0.0.0.0:8000 --reload --worker-class=gevent --worker-connections=1000 --workers 3 --timeout 120

  docs:
    image: kenguru_local_docs
    container_name: docs
    build:
      context: .
      dockerfile: ./docker/local/docs/Dockerfile
    env_file:
      - ./.envs/.local/.django
    volumes:
      - ./docs:/docs
      - ./config:/app/config
      - ./project:/app/project
    ports:
      - "7000:7000"
    expose:
      - 7000

Dockerfile:
FROM python:3.7-slim-buster

ENV PYTHONUNBUFFERED 1

RUN apt-get update \
  # dependencies for building Python packages
  && apt-get install -y build-essential \
  # psycopg2 dependencies
  && apt-get install -y libpq-dev \
  # Translations dependencies
  && apt-get install -y gettext \
  # cleaning up unused files
  && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
  && rm -rf /var/lib/apt/lists/*

RUN pip install sphinx && pip install sphinx-rtd-theme

WORKDIR /docs

CMD make html


After a successful make html run, the container shuts down. How to make the documentation permanently hanging on this port? Or are there some other ways?

After the command, a generated _build/html folder is created in which an index.html file is needed as the initial one for this port.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NubasLol, 2021-02-11
@NubasLol

Here's how you can assemble

FROM python:3.7-slim-buster as docs

ENV PYTHONUNBUFFERED 1

RUN apt-get update \
  # dependencies for building Python packages
  && apt-get install -y build-essential \
  # psycopg2 dependencies
  && apt-get install -y libpq-dev \
  # Translations dependencies
  && apt-get install -y gettext \
  # cleaning up unused files
  && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
  && rm -rf /var/lib/apt/lists/*

RUN pip install sphinx && pip install sphinx-rtd-theme

WORKDIR /docs

CMD make html

###

FROM nginx:latest as nginx

COPY --from=docs /docs /var/www/html/public

CMD ["nginx", "-g", "daemon off;"]

and in docker-compose use only nginx, which will contain html docks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question