bugy / script-server

Web UI for your scripts with execution management
Other
1.52k stars 243 forks source link

How do you use this to run docker commands? #735

Open mmkk20158 opened 4 months ago

mmkk20158 commented 4 months ago

So I installed this on my docker server and i'd like people to be able to restart a service on another docker. obviosly since this is inside a docker itself it doens't have access to the hosts info.

basically i'm hosting a palworld server and i want my users to be able be able to restart the docker container for updates / mods / etc

bugy commented 4 months ago

Hey, i guess this is not a question about script server, but rather docker and container management. Your goal is to write a script which will work inside a docker container. Script server will just give a web access to this script. I think this guide might be helpful https://www.reddit.com/r/docker/comments/169hnti/quick_guide_how_to_control_a_docker_host_from/

mmkk20158 commented 4 months ago

hey thanks! yeah i know i can use the api but was just curious if there was some other way without opening a port.

thanks again!

bugy commented 4 months ago

Yep, unfortunately Script server doesn't have any special features for docker

mmkk20158 commented 4 months ago

Yep, unfortunately Script server doesn't have any special features for docker

what's the recommended way to add curl to the container? i tried a volume binding but then all of the dependancis aren't there

mmkk20158 commented 4 months ago

I just used the python3 that was included ayway, for anyone in the future

#!/usr/local/bin/python3
import http.client

palworld_container = "71cc9de67538"
docker_host = "172.17.0.1"
docker_port = 2375

restart_path = f"/containers/{palworld_container}/restart"

print("connecting to docker host...")
connection = http.client.HTTPConnection(docker_host, docker_port, timeout=100)

print(f"REST API call: POST {restart_path}")
connection.request("POST", restart_path)
response = connection.getresponse()

print("Resonse:")
if ( response.status == 204):
    print("Success")
else:
    print(f"{response.status}    {response.reason}")
bugy commented 4 months ago

Thanks a lot @mmkk20158 !

agail commented 2 months ago

Yep, unfortunately Script server doesn't have any special features for docker

what's the recommended way to add curl to the container? i tried a volume binding but then all of the dependancis aren't there

You could use a staging script* once the container is up to install additional packages or customize your image with docker compose to add the packages you need.

#!/bin/bash
# placed at shared directory with the container

apt update
apt install package1 package2 package3
apt clean