Voting-App

Project Source Code: https://github.com/dockersamples/example-voting-app.git

Tasks:

Running Only voting-app:
Running with Redis attached:
Running with postgres and worker-app
Running with result-app finally

Pasted image 20231103131614.png
Pasted image 20231103131644.png

Running with docker-compose

docker-compose.yml file

# version is now using "compose spec"
# v2 and v3 are now combined!
# docker-compose v1.27+ required

services:
  vote:
    build: 
      context: ./vote
      target: dev
    depends_on:
      redis:
        condition: service_healthy
    healthcheck: 
      test: ["CMD", "curl", "-f", "http://localhost"]
      interval: 15s
      timeout: 5s
      retries: 3
      start_period: 10s
    volumes:
     - ./vote:/usr/local/app
    ports:
      - "5000:80"
    networks:
      - front-tier
      - back-tier

  result:
    build: ./result
    # use nodemon rather than node for local dev
    entrypoint: nodemon --inspect=0.0.0.0 server.js
    depends_on:
      db:
        condition: service_healthy 
    volumes:
      - ./result:/usr/local/app
    ports:
      - "5001:80"
      - "127.0.0.1:9229:9229"
    networks:
      - front-tier
      - back-tier

  worker:
    build:
      context: ./worker
    depends_on:
      redis:
        condition: service_healthy 
      db:
        condition: service_healthy 
    networks:
      - back-tier

  redis:
    image: redis:alpine
    volumes:
      - "./healthchecks:/healthchecks"
    healthcheck:
      test: /healthchecks/redis.sh
      interval: "5s"
    networks:
      - back-tier

  db:
    image: postgres:15-alpine
    environment:
      POSTGRES_USER: "postgres"
      POSTGRES_PASSWORD: "postgres"
    volumes:
      - "db-data:/var/lib/postgresql/data"
      - "./healthchecks:/healthchecks"
    healthcheck:
      test: /healthchecks/postgres.sh
      interval: "5s"
    networks:
      - back-tier

  # this service runs once to seed the database with votes
  # it won't run unless you specify the "seed" profile
  # docker compose --profile seed up -d
  seed:
    build: ./seed-data
    profiles: ["seed"]
    depends_on:
      vote:
        condition: service_healthy 
    networks:
      - front-tier
    restart: "no"

volumes:
  db-data:

networks:
  front-tier:
  back-tier:

run docker-compose up
check out : http://localhost:5000
and http://localhost:5001

And this project is done.


Pasted image 20231028161523.png

Setup for Podman:

  1. Create a common network for both our pods:
    podman network create my-network

  2. Create a Pod and Specify Port Mapping:
    podman pod create --name my-pod -p 5000:80 --network my-network

  3. Run Containers Inside the pod:

podman run -d --name redis --pod my-pod redis
podman run -d --name voting-app --pod my-pod voting-app
podman run -d --name db -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres --pod my-pod -v /data:/var/lib/postgresql/data postgres
podman run -d --name worker-app --pod my-pod worker-app 
  1. Create a new pod with the desired port mapping:
    podman pod create --name my-new-pod -p 5001:80 --network my-network

  2. Start the "result-app" container inside the new pod:
    podman run --name result-app --pod my-new-pod result-app
    or try this:
    podman run -p 5001:80 --name result-app --pod my-new-pod --network my-pod result-app

The Issue is Postgres is failing, because its database is not initiated.
Its should be initialized with these commands:

CREATE DATABASE mydatabase; 
CREATE USER myuser WITH PASSWORD 'mypassword'; 
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;

Update: Even tho after successfully solving postgress error it still not seems to communicate with pod 1.