Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: [CoD2] Setup CoD2 with Docker

  1. #1
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    86
    Thanks
    82
    Thanked 38 Times in 25 Posts

    [CoD2] Setup CoD2 with Docker


    About

    Hello all. I want to show you how we can use CoD2 server in Docker container.

    I tried IzNoGoD's method, I wrote my own and after some time I started to use Docker at home and at work then, in production. At this moment, I run 2 my CoD2 servers in Docker. Now I want to share my experience to Killtube.

    Advantages of this method:
    1. In my opinion, this method is much easier than IzNoGoD's;
    2. And much more stable than my old one;
    3. All CoD2 versions;
    4. In this method you don't have to use specific OS (e.g. Ubuntu 14.04). You can use even Windows and still have libcod;
    5. You don't have to install any of CoD2 requirements to your system;
    6. Libcod already installed. If you have to use specific version or repo - you can change it in arguments;
    7. Last cod2_lnxded versions installed;
    8. Auto-restarting server on crash;
    9. Server health monitoring (with getinfo);
    10. Logging.


    And before we start: all steps here I write for Linux. If you really want to have CoD2 server on Windows - there's no really much job, but all these steps you should convert by yourself.

    So, let's start!


    Requirements

    Docker and Docker-Compose

    Docker is a computer program that performs operating-system-level virtualization, also known as "containerization". Docker is used to run software packages called "containers". Containers are isolated from each other and bundle their own application, tools, libraries and configuration files; they can communicate with each other through well-defined channels. All containers are run by a single operating-system kernel and are thus more lightweight than virtual machines. Containers are created from "images" that specify their precise contents. Images are often created by combining and modifying standard images downloaded from public repositories.
    (c) Wikipedia


    Compose is a tool for defining and running multi-container Docker applications.
    (c) Docker documentation


    First of all, let's install Docker:
    Code:
    sudo curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh
    And Docker-Compose:
    Code:
    sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose
    If you don't want to always write sudo to use Docker - give a permissions to your user:
    Code:
    sudo usermod $(whoami) -aG docker

    Files

    I left my docker image almost empty (for legal reasons also), so you have to upload these files to your server:
    1. main folder of your cod2
    2. fs_game of your server
    3. your maps (optional)


    You can put it anywhere you want on your server. For example: I put it like this (~ is a home dir):
    1. ~/cod2/main
    2. ~/cod2/myserver
    3. ~/cod2/Library



    Get CoD2 image

    Docker image - is like a template for containers. You can pull it once and make a lot of containers on it. So you can save a lot of disk space on it.

    You have 2 ways how to get the image:
    1. I created a repo in Docker Hub, so you can pull the image from the web.
    2. I also created a GitHub repo, where you can get a Dockerfile to create a Docker image by yourself.


    If you more like the first way - no need to do now, pass this stage and move to the next one.

    If you want to build your own image (with arguments, maybe), let's zoom in it:
    1. Clone the repo
    2. Edit build.sh file with your parameters (you can look available parameters on the top of Dockerfile)
    3. Execute it!



    Setup container

    Now we will setup our container (server) with a compose file. Create a file called docker-compose.yml (or just copy it from my repo). It's a basic text config file. Put there this text and then we will change it on your needs:

    Code:
    # example for 1.0 cod2 server
    version: '3.7'
    services:
      myserver:
        image: lonsofore/cod2:1.0
        container_name: myserver
        restart: always
        stdin_open: true
        tty: true
        network_mode: host
        volumes:
         - ~/cod2/main:/cod2/main
         - ~/cod2/myserver:/cod2/myserver
         - ~/cod2/Library:/cod2/.callofduty2/server/Library
        environment:
         PARAMS: "+set fs_homepath /cod2/.callofduty2/ +set fs_game myserver +set dedicated 2 +set net_port 28960 +exec myserver.cfg"
         CHECK_PORT: 28960
    In this file you should change only 2 things:
    1. Volumes. It's a folders or files which would be available from the container. Format: local:container. You can see the file structure that I used in the example above. Change it on your needs. If you don't have custom maps - you can delete a line with Library.
    2. Environment. It's your server settings. PARAMS is what would be executed by your server. Change fs_game, port and server cfg name to yours there. CHECK_PORT - also your server port, it used to monitore container health.



    Run

    Ok, after all these changes we're ready to start our container.

    Write in console: docker-compose up -d

    If everything is ok, you can see your container in containers list. Write: docker ps

    In STATUS field you can see container's health. After one or two minutes it should be 'healthy'.

    To see server logs write: docker logs ID

    To attach your container and use server console copy your server's ID from list (first column) and write: docker attach ID

    To deattach press Ctrl+P and then Ctrl+Q.


    Advanced part (optional)

    Your own Docker image

    If your server has some system requirements (like a apt libs) you can create your own image based on mine. It's very easy! For example, I want to show you a Dockerfile of my own server:

    Code:
    FROM lonsofore/cod2:1.0
    
    # vodka requirements
    RUN apt-get update \
        && apt-get install -y \
            python3 \
            python3-pip \
            geoip-bin \
        && rm -rf /var/lib/apt/lists \
        && pip3 install geoip2
    All you need is just install your requirements. In my case, I leave ENTRYPOINT command and use it from the base image. If you want to change it for some reason - copy it from base image to preload libcod.


    Server restarts

    There are two types of restarts:

    1. If CoD2 would stop for some reason (e.g. ShutdownGame) - Docker will restart it automatically ('restart' part in docker-compose.yml)
    2. If for some reason CoD2 would still run, but health check (you can look that part in Dockerfile. it's just a getinfo from the server, which takes each 5 seconds 3 times) would fail (e.g. server just freezed) - docker container would be marked as 'unhealthy'. But! In this case, the container wouldn't restart automatically - there is no such functionality in Docker. In this case you should use some tool, which would process it. For my server I use a docker image called autoheal. An example of my docker-compose.yml for autoheal:
      Code:
      version: '3.7'
        services:
          autoheal:
            image: willfarrell/autoheal
            container_name: autoheal
            restart: always
            volumes:
             - /var/run/docker.sock:/var/run/docker.sock
            environment:
             AUTOHEAL_CONTAINER_LABEL: "all"
      AUTOHEAL_CONTAINER_LABEL with value "all" means that all unhealthy containers would be restarted.

    So, your server should be up even after freeze or something like.


    Logging

    As I said before, you always can look a full log via 'docker logs <container id>'. But if you also want to see a log file, you can find it here:
    /var/lib/docker/containers/<container id>/<container id>-json.log

    Credits

    In this part I just want to say thank you to kung foo man and IzNoGoD. They helped me a lot in Killtube Discord chat.


    Links

    DockerHub
    GitHub
    Last edited by Lonsofore; 26th April 2019 at 22:47.

  2. The Following 4 Users Say Thank You to Lonsofore For This Useful Post:

    amnesia (21st May 2019),kung foo man (25th February 2019),vanfreddy (25th February 2019),Whiskas (25th February 2019)

  3. #2
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Where is the logging and auto restart part? How do u manage that?

  4. The Following User Says Thank You to Ni3ls For This Useful Post:

    Lonsofore (27th February 2019)

  5. #3
    Sergeant maxdamage99's Avatar
    Join Date
    Aug 2014
    Location
    Russia
    Posts
    458
    Thanks
    79
    Thanked 122 Times in 101 Posts
    Auto-restart after CoD2 engine errors (==== ShutdownGame ====) too or only after CoD2 process crash?
    PHP Code:
    class CoronaVirus 
    {
       
    CoronaVirus(int m 1): multi(m) { Peoples.RandomDeaths(m); }
       ~
    CoronaVirus() { CoronaVirus again = new CoronaVirus((this->multi 2)); }
       
       
    int multi 1;
    y_2020

  6. The Following User Says Thank You to maxdamage99 For This Useful Post:

    Lonsofore (27th February 2019)

  7. #4
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    86
    Thanks
    82
    Thanked 38 Times in 25 Posts
    Agree, I missed these parts. Few words about restarts:

    1. If CoD2 would stop for some reason (e.g. ShutdownGame, as Damage said) - Docker will restart it automatically ('restart' part in docker-compose.yml)
    2. If for some reason CoD2 would still run, but health check (you can look that part in Dockerfile. it's just a getinfo from the server, which takes each 5 seconds 3 times) would fail (e.g. server just freezed) - docker container would be marked as 'unhealthy'. But! In this case, the container wouldn't restart automatically - there is no such functionality in Docker. In this case you should use some tool, which would process it. For my server I use a docker image called autoheal. An example of my docker-compose.yml for autoheal:
      Code:
      version: '3.7'
        services:
          autoheal:
            image: willfarrell/autoheal
            container_name: autoheal
            restart: always
            volumes:
             - /var/run/docker.sock:/var/run/docker.sock
            environment:
             AUTOHEAL_CONTAINER_LABEL: "all"
      AUTOHEAL_CONTAINER_LABEL with value "all" means that all unhealthy containers would be restarted.

    So, your server should be up even after freeze or something like.


    About logging:
    As I said before, you always can look a full log via 'docker logs <container id>'. But if you also want to see a log file, you can find it here:
    /var/lib/docker/containers/<container id>/<container id>-json.log


    I pinned this answer to the head, in Advanced part.
    Last edited by Lonsofore; 28th February 2019 at 08:14.

  8. #5
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Merge support for https://pterodactyl.io/ maybe?

    (I'm not using it, but seems like the best free game panel on the market today, using docker)
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  9. The Following User Says Thank You to IzNoGoD For This Useful Post:

    Mitch (19th September 2020)

  10. #6
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    86
    Thanks
    82
    Thanked 38 Times in 25 Posts
    Quote Originally Posted by IzNoGoD View Post
    Merge support for https://pterodactyl.io/ maybe?

    (I'm not using it, but seems like the best free game panel on the market today, using docker)
    Well, looks interesting, but:
    1. What do you mean with "merge support"?
    2. It's a panel to manage games in Docker containers, with a lot of dependencies, but... it isn't in Docker container. That's strange for me.

    P.S. GUI is really nice
    Last edited by Lonsofore; 28th February 2019 at 08:15.

  11. #7
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    86
    Thanks
    82
    Thanked 38 Times in 25 Posts
    Update.

    * Now you don't have to download cod2_lnxded - it's included to image.
    * Moved from i386 ubuntu architecture to amd64. Did it only because of child images with different programs (like a image of my server).

  12. #8
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    86
    Thanks
    82
    Thanked 38 Times in 25 Posts
    Up!

    Optimized Docker layers;
    Extended healthcheck retries (CaptainSlow had some errors with false-positive healthchecks on map-restart);
    Updated libcod version to latest;
    Uploaded all version to Docker Hub!

  13. The Following User Says Thank You to Lonsofore For This Useful Post:

    kung foo man (15th May 2020)

  14. #9
    Private CaptainSlow's Avatar
    Join Date
    Nov 2014
    Posts
    76
    Thanks
    38
    Thanked 28 Times in 23 Posts
    Heads up: Docker is making changes to their image retention policy on Docker Hub. Inactive images, defined as images that have not been pulled or pushed in 6 months, will be deleted from Docker Hub starting November 1, 2020.
    So please make sure to (automatically) rebuild your image at least every 6 months or nobody will be able to pull the image anymore..... which would be a shame, because it's a great image
    Slow and Steady wins the race

  15. The Following 2 Users Say Thank You to CaptainSlow For This Useful Post:

    kung foo man (2nd September 2020),Lonsofore (18th September 2020)

  16. #10
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    86
    Thanks
    82
    Thanked 38 Times in 25 Posts
    Quote Originally Posted by CaptainSlow View Post
    Heads up: Docker is making changes to their image retention policy on Docker Hub. Inactive images, defined as images that have not been pulled or pushed in 6 months, will be deleted from Docker Hub starting November 1, 2020.
    So please make sure to (automatically) rebuild your image at least every 6 months or nobody will be able to pull the image anymore..... which would be a shame, because it's a great image
    Thank you for the information! I think, it's easier to make a cron-task to pull the image every month. Actually, even without the image on Docker Hub it's always possible to build it on your own machine with the Github repo.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •