Results 1 to 6 of 6

Thread: [CoD2] Setup CoD2 with Docker

  1. #1
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    81
    Thanks
    81
    Thanked 35 Times in 23 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. Auto-restarting server on crash;
    8. Server health monitoring (with getinfo);
    9. 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. cod2_lnxded for your server version
    4. 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/cod2_lnxded
    4. ~/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/cod2_lnxded_1_0:/cod2/cod2_lnxded
         - ~/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; 27th February 2019 at 21:22.

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

    kung foo man (25th February 2019),vanfreddy (25th February 2019),Whiskas (25th February 2019)

  3. #2
    Brigadier General
    Join Date
    Dec 2012
    Posts
    992
    Thanks
    436
    Thanked 165 Times in 127 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
    370
    Thanks
    74
    Thanked 85 Times in 71 Posts
    Auto-restart after CoD2 engine errors (==== ShutdownGame ====) too or only after CoD2 process crash?
    write shit code's

  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
    81
    Thanks
    81
    Thanked 35 Times in 23 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,575
    Thanks
    17
    Thanked 921 Times in 574 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

    Sending me a private message makes me want to help you LESS.

  9. #6
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    81
    Thanks
    81
    Thanked 35 Times in 23 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.

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
  •