MitchTalmadge / AMP-dockerized

CubeCoders AMP in a Docker Image. Easily create game servers for games like Minecraft, GMod, TF2, Factorio, and StarBound!
https://hub.docker.com/r/mitchtalmadge/amp-dockerized
Other
91 stars 22 forks source link

[Feature Request] Trying to get Amp to use the hosts docker #100

Open Joly0 opened 2 years ago

Joly0 commented 2 years ago

Its possible for containers (such as portainer) to hook into the hosts docker engine through a docker.sock. Using that, those containers are able to create more containers on the host os.

Amp already has the option to create instances in docker containers. It would be great (especially for opening ports) if it would be possible to have a master instance with this image running ads and telling it to create instances in containers using a docker.sock which creates them on the host os.

Though i am not sure, if this does work currently with amp (or ever), if some capabilities are missing or not (havent tested, this is just a suggestion for something it might be useful to look into). In theory this could work, which would mean, we just need this image for ads (smaller size, better maintainability and more) and could use the official ones for the game instances.

Joly0 commented 2 years ago

https://support.cubecoders.com/thread/help-on-setting-amp-in-a-docker-container/ some points where outlined here already 2 years ago (i posted my own amp container there back then lol)

MitchTalmadge commented 2 years ago

I have wondered the same thing. I will have to look into this

Joly0 commented 2 years ago

I had some time tinkering with this idea though i dont get it to work as intended.

I installed docker inside the container and added the hosts docker socket through a volume (that should in theory work) but amp was unable to create instances like that.

I am not sure, if amp maybe completly ignores the socket and just directly uses docker itself (which might be plausible) and would result in this feature to fail, unless we come up with a proper workaround.

Other than that there are several projects like DinD (Docker-in-Docker) which sound like they are what we need, but it also sounds like a big change to the docker as it is currently.

Maybe i can further test this in the next days/weeks but this is, unfortunately, what i found

ouvoun commented 2 years ago

This would be a brilliant change, and probably would alleviate most of the compatibility issues this container seems to have with new games.

Seemingly the Docker-in-Docker container might fit the bill. I wonder how difficult it would be to rebase this container using that as the base?

xionous commented 1 year ago

I had some time tinkering with this idea though i dont get it to work as intended.

I installed docker inside the container and added the hosts docker socket through a volume (that should in theory work) but amp was unable to create instances like that.

I am not sure, if amp maybe completly ignores the socket and just directly uses docker itself (which might be plausible) and would result in this feature to fail, unless we come up with a proper workaround.

Other than that there are several projects like DinD (Docker-in-Docker) which sound like they are what we need, but it also sounds like a big change to the docker as it is currently.

Maybe i can further test this in the next days/weeks but this is, unfortunately, what i found

There is a reason it didn't work for you, it needs more then just the docker socket. a lot more.

If you want to get this to work you need to do a few things:

  1. bind mount the docker socket from the host
  2. bind mount a directory from the host to place instances into that is identical file path on the host and in the main AMP container. This is needed because the instance container on the host will create it's appdata in a folder on the host machine and the AMP container needs to be able to read/write info to that directory
  3. add a datastore in the AMP UI that uses the aforementioned volume to store instances *
  4. make sure to select the correct datastore when you create an instance ****
  5. change the auth URL config option in new instance defaults to be the host.ip:port so the outside container can reach the AMP auth end point ***
  6. enable create in docker in new instance defaults ***
  7. change the network config in AMP to not use the host network so that it uses the default bridge network for the outside containers **
  8. change the default AMP binding ip to 0.0.0.0 in network config **
  9. change the service port range in networking to one that is available on the host system **
  10. bind mount the scripts folder from the install instructions and create a files called startup.sh in it
  11. add the following stuff to that file (it will install docker and set some things up on startup to allow the management of instances to work):

    #!/bin/bash
    # make sure change `groupmod -g 281 docker` to match the group ID of docker on your host so the group ID is identical between the container and host.
    apt update; apt -y install apt-transport-https ca-certificates curl software-properties-common; curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -; add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"; apt -y install docker-ce; usermod -aG docker amp; groupmod -g 281 docker; apt -y install nginx
    cat > /etc/nginx/sites-enabled/default <<EOF
    server {
    listen 8081;
    
    location / {
        proxy_pass http://host-ip:8081;
    }
    }
    # you can create multiple copies of this block, 1 for each instance and the port it uses. the ports must match the port each instance uses. you can create as many as you think you will need, server blocks that are not used will not cause an issue.
    # be sure to change the host-ip part to your hosts IP address
    server {
    listen 8082;
    
    location / {
        proxy_pass http://host-ip:8082;
    }
    }
    EOF
    service nginx restart

Some images: * image ** image *** image **** image

Dalarialus commented 1 year ago

It may be worth looking into nestybox/sysbox for this - it's a lot more secure than DinD, and less kludgey than other workarounds. It would require changes to the base image to add things like systemd, but once implemented it should be stable and secure - it doesn't even need to be run in a privileged container!

xionous commented 1 year ago

It may be worth looking into nestybox/sysbox for this - it's a lot more secure than DinD, and less kludgey than other workarounds. It would require changes to the base image to add things like systemd, but once implemented it should be stable and secure - it doesn't even need to be run in a privileged container!

My solution is not DinD it only installs Docker to use the binary to talk to the Docker socket on the host system which is bind mounted to the container. Also my solution does not require a privileged container.