docker-compose.yml 3.09 KB
version: "3.9"

services:
  db:
    # if we're using mysql >= 8, some of sql queries aren't valid anymore, like for creating and grant an user at the same time
    # This is fixed in pyros.py
    image: mysql:8.0.28
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    container_name: pyros-db
    environment:
      # note : as db is an image of mysql, this root password will be set on the first installation on the image, if the value is changed, it will not be updated in the database
      - "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root}"
      - VNC_NO_PASSWORD=1
    volumes:
      - db:/var/lib/mysql/
    # create network to allow images to communicate with other images within the same network 
    networks: 
      pyros-network: 
        ipv4_address: 172.19.0.2

    healthcheck:
      test: ["CMD", 'mysqladmin', 'ping', '-h', 'db', '-u', 'root', '-p$$MYSQL_ROOT_PASSWORD' ]
      timeout: 10s
      interval: 5s
      retries: 20

  # service image of python, that let users to interact with python scripts such as pyros.
  pyros:
    # path to the Dockerfile of this image
    environment:
      # environment variables only for Docker
      - WITH_DOCKER=y
      # disabling other env variables because they will override those from the env_file
      # - MYSQL_ROOT_LOGIN=root
      # - MYSQL_TCP_PORT=3306
      # environment variables available for both Docker usage and non Docker usage
      # - "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root}"
      # - "MYSQL_PYROS_LOGIN=${MYSQL_PYROS_LOGIN:-pyros}"
      # - "MYSQL_PYROS_PWD=${MYSQL_PYROS_PWD:-DjangoPyros}"
      #- "IP_PYROS_USER=${IP_PYROS_USER:-172.28.1.5}"
    env_file: 
      - .env
    build: 
      args:
        uid: ${CURRENT_UID}
      context: ..
        #filename: Dockerfile
    container_name: pyros
    hostname: ${COMPUTER_HOSTNAME}
    # tty is the -t option in docker exec 
    tty: true
    # stdin_open is the -i option in docker exec
    stdin_open: true
    volumes:
      - ..:/home/pyros_user/app
    # tells which port of local machine can communicate with the docker image (host:container), host is your local machine
    ports:
      - "${PYROS_WEBSITE_PORT:-8000}:${PYROS_WEBSITE_PORT:-8000}"
      - 5900:5900
    # starting db service before install service 
    depends_on:
      - db
    # create network to allow images to communicate with other images within the same network 
    networks: 
      pyros-network:
        ipv4_address: 172.19.0.3
        #ipv4_address: "${IP_PYROS_USER}"
    restart: always
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: pyros-pma
    links:
      - db
    environment:
      PMA_HOST: db
      PMA_PORT: 3306
      PMA_ARBITRARY: 1
    env_file: 
      - .env
    restart: always
    networks: 
      pyros-network:
        ipv4_address: 172.19.0.4
    ports:
      - "${PHPMYADMIN_PORT:-8081}:80"

# declaring volumes
volumes:
  db:
    driver: local
# declaring networks
networks: 
  pyros-network:
    #bridge is the default network driver
    driver: bridge
    ipam:
      config:
        - subnet: 172.19.0.0/16
          gateway: 172.19.0.1