Shoulder.dev Logo Shoulder.dev

Docker - screenly/anthias

Docker and Containerization in Anthias Project

Docker is an open-source platform that automates the deployment, scaling, and management of applications using containerization technology. Docker allows developers to package an application and its dependencies into a single container that can run consistently across different environments.

In the Anthias project, Docker is used to containerize various services, including the server, websocket, celery, redis, nginx, viewer, and wifi-connect. This helps to ensure that the application runs consistently across different platforms and environments.

Docker Compose

Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to define a multi-container application in a YAML file, which can be used to create and start all the services with a single command.

In the Anthias project, Docker Compose is used to define and manage the various services that make up the application. The docker-compose.yml file in the root of the project defines the various services, including their dependencies, environment variables, and volumes.

Here's an example of the docker-compose.yml file in the Anthias project:

version: "2"
services:
  anthias-server:
    build:
      context: .
      dockerfile: docker/Dockerfile.server
    environment:
      - HOME=/data
      - LISTEN=0.0.0.0
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
    devices:
      - "/dev/vchiq:/dev/vchiq"
    restart: always
    volumes:
      - resin-data:/data
      - /home/${USER}/.screenly:/data/.screenly
      - /home/${USER}/screenly_assets:/data/screenly_assets
      - /home/${USER}/screenly/static:/data/screenly/static
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    labels:
      io.balena.features.supervisor-api: '1'
  anthias-viewer:
    build:
      context: .
      dockerfile: docker/Dockerfile.viewer
    mem_limit: ${VIEWER_MEMORY_LIMIT_KB}k
    depends_on:
      - anthias-server
    environment:
      - HOME=/data
      - PORT=80
      - NOREFRESH=1
      - LISTEN=anthias-nginx
    extra_hosts:
      - "host.docker.internal:host-gateway"
    privileged: true
    restart: always
    volumes:
      - resin-data:/data
      - /home/${USER}/.screenly:/data/.screenly
      - /home/${USER}/screenly_assets:/data/screenly_assets
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    labels:
      io.balena.features.supervisor-api: '1'
  anthias-websocket:
    build:
      context: .
      dockerfile: docker/Dockerfile.websocket
    depends_on:
      - anthias-server
    environment:
      - HOME=/data
      - LISTEN=0.0.0.0
    restart: always
    volumes:
      - resin-data:/data
      - /home/${USER}/.screenly:/data/.screenly
      - /home/${USER}/screenly_assets:/data/screenly_assets
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
  redis:
    image: screenly/anthias-redis:${DOCKER_TAG}-${DEVICE_TYPE}
    build:
      context: .
      dockerfile: docker/Dockerfile.redis
    ports:
      - 127.0.0.1:6379:6379
    restart: always
    volumes:
      - redis-data:/var/lib/redis
volumes:
  resin-data:
  redis-data:

Dockerfile

A Dockerfile is a script that contains instructions for building a Docker image. In the Anthias project, there are several Dockerfiles for building the various services that make up the application.

Here's an example of the Dockerfile.server in the Anthias project:

FROM ${BASE_IMAGE}:${BASE_IMAGE_TAG}

# This list needs to be trimmed back later
RUN --mount=type=cache,target=/var/cache/apt \
    apt-get update && \
    apt-get -y install --no-install-recommends \
        build-essential \
        ca-certificates \
        fonts-arphic-uming \
        git-core \
        libasound2-dev \
        libavcodec-dev \
        libavformat-dev \
        libavutil-dev \
        libbz2-dev \
        libcec-dev \
        libdbus-1-dev \
        libdbus-glib-1-dev \
        libdrm-dev \
        libegl1-mesa-dev \
        libevent-dev \
        libffi-dev \
        libfontconfig1-dev \
        libfreetype6-dev \
        libgbm-dev \
        libgcrypt20-dev \
        libgles2-mesa \
        libgles2-mesa-dev \
        libglib2.0-dev \
        libgst-dev \
        libicu-dev \
        libinput-dev \
        libiodbc2-dev \
        libjpeg62-turbo-dev \
        libjsoncpp-dev \
        libminizip-dev \
        libnss3 \
        libnss3-dev \
        libopus-dev \
        libpci-dev \
        libpng-dev \
        libpng16-16 \
        libpq-dev \
        libpulse-dev \
        libraspberrypi0 \
        librsvg2-common \
        libsdl2-dev \
        libsnappy-dev \
        libsqlite0-dev \
        libsqlite3-dev \
        libsrtp0-dev \
        libsrtp2-dev \
        libssl-dev \
        libzmq3-dev \
        libssl1.1 \
        libswscale-dev \
        libsystemd-dev \
        libts-dev \
        libudev-dev \
        libvpx-dev \
        libwebp-dev \
        libx11-dev \
        libx11-xcb-dev \
        libx11-xcb1 \
        libxcb-glx0-dev \
        libxcb-icccm4 \
        libxcb-icccm4-dev \
        libxcb-image0 \
        libxcb-image0-dev \
        libxcb-keysyms1 \
        libxcb-keysyms1-dev \
        libxcb-randr0-dev \
        libxcb-render-util0 \
        libxcb-render-util0-dev \
        libxcb-shape0-dev \
        libxcb-shm0 \
        libxcb-shm0-dev \
        libxcb-sync-dev \
        libxcb-sync1 \
        libxcb-xfixes0-dev \
        libxcb-xinerama0 \
        libxcb-xinerama0-dev \
        libxcb1 \
        libxcb1-dev \
        libxext-dev \
        libxi-dev \
        libxkbcommon-dev \
        libxrender-dev \
        libxslt1-dev \
        libxss-dev \
        libxtst-dev \
        libzmq5-dev \
        libzmq5 \
        net-tools \
        omxplayer \
        psmisc \
        python3-dev \
        python3-gi \