QingdaoU / OnlineJudgeDeploy

529 stars 364 forks source link

host two oj in one machine #38

Closed simbafs closed 4 years ago

simbafs commented 4 years ago

I want to host two OJ in one machine. One for public and one for testing. I try this:

version: "3"                                                                                                                                           
services:                                                                                                                                              

  toj-redis:                                                                                                                                           
    image: redis:4.0-alpine                                                                                                                            
    container_name: toj-redis                                                                                                                          
    restart: always                                                                                                                                    
    volumes:                                                                                                                                           
      - ./data/redis:/data                                                                                                                             
    ports:                                                                                                                                             
      - "0.0.0.0:6379:6389"                                                                                                                            

  toj-postgres:                                                                                                                                        
    image: postgres:10-alpine                                                                                                                          
    container_name: toj-postgres                                                                                                                       
    restart: always                                                                                                                                    
    volumes:                                                                                                                                           
      - ./data/postgres:/var/lib/postgresql/data                                                                                                       
    environment:                                                                                                                                       
      - POSTGRES_DB=onlinejudge                                                                                                                        
      - POSTGRES_USER=onlinejudge                                                                                                                      
      - POSTGRES_PASSWORD=onlinejudge                                                                                                                  
    ports:                                                                                                                                             
      - "0.0.0.0:5432:5442"                                                                                                                            

  toj-judge-server:                                                                                                                                    
    image: registry.cn-hangzhou.aliyuncs.com/onlinejudge/judge_server                                                                                  
    container_name: toj-judge-server                                                                                                                   
    restart: always                                                                                                                                    
    read_only: true
    cap_drop:
      - SETPCAP
      - MKNOD
      - NET_BIND_SERVICE
      - SYS_CHROOT
      - SETFCAP
      - FSETID
    tmpfs:
      - /tmp/toj
    volumes:
      - ./data/backend/test_case:/test_case:ro
      - ./data/judge_server/log:/log
      - ./data/judge_server/run:/judger
    environment:
      - SERVICE_URL=http://judge-server:8090
      - BACKEND_URL=http://toj-backend:8010/api/judge_server_heartbeat/
      - TOKEN=CHANGE_THIS
      # - judger_debug=1
    ports:
      - "0.0.0.0:8080:8090"

  toj-backend:
    image: registry.cn-hangzhou.aliyuncs.com/onlinejudge/oj_backend
    container_name: toj-backend
    restart: always
    depends_on:
      - toj-redis
      - toj-postgres
      - toj-judge-server
    volumes:
      - ./data/backend:/data
    environment:
      - POSTGRES_DB=onlinejudge
      - POSTGRES_USER=onlinejudge
      - POSTGRES_PASSWORD=onlinejudge
      - JUDGE_SERVER_TOKEN=CHANGE_THIS
      # - FORCE_HTTPS=1
      # - STATIC_CDN_HOST
    ports:
      - "0.0.0.0:8000:8010"
      - "0.0.0.0:1443:1453"

But I got error:

WARNING: Found orphan containers (oj-backend, judge-server, oj-postgres, oj-redis) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Recreating toj-redis ...
Recreating toj-judge-server ...
Recreating toj-redis
Recreating toj-postgres ...
Recreating toj-judge-server
Recreating toj-postgres ... done
Recreating toj-backend ...
Recreating toj-backend ... error

ERROR: for toj-backend  Cannot start service toj-backend: driver failed programming external connectivity on endpoint toj-backend (2eb41d38fa28dbd8adde8ba7605673c517e3027a9dbd2542bc658c588fe15031): Bind for 0.0.0.0:8000 failed: port is already allocated

ERROR: for toj-backend  Cannot start service toj-backend: driver failed programming external connectivity on endpoint toj-backend (2eb41d38fa28dbd8adde8ba7605673c517e3027a9dbd2542bc658c588fe15031): Bind for 0.0.0.0:8000 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.

by the way, toj mean testing oj

virusdefender commented 4 years ago

you should change the listen port

simbafs commented 4 years ago

Sorry I'm new in docker @virusdefender which port did you mean?
toj-backend or what? I have change every port that I know and I even change the names of the container.

jerrywcy commented 4 years ago

One of your OJs is listening at port 8080, so the other one can't.