Skip to content

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

@mmkk20158

Description

@mmkk20158

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

Activity

bugy

bugy commented on Feb 15, 2024

@bugy
Owner

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

mmkk20158 commented on Feb 15, 2024

@mmkk20158
Author

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

bugy commented on Feb 16, 2024

@bugy
Owner

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

mmkk20158

mmkk20158 commented on Feb 16, 2024

@mmkk20158
Author

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

mmkk20158 commented on Feb 17, 2024

@mmkk20158
Author

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

bugy commented on Feb 20, 2024

@bugy
Owner

Thanks a lot @mmkk20158 !

agail

agail commented on Apr 15, 2024

@agail

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
ClarkeAC

ClarkeAC commented on Aug 15, 2024

@ClarkeAC
Contributor

What about mount docker and its sock? In this case it is possible to use docker xxx without having to install docker in docker.

services:
  script-server:
    image: bugy/script-server:latest
    restart: unless-stopped
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker # ${which docker}:/usr/bin/docker
      - ./script-server/conf.json:/app/conf/conf.json
      - ./script-server/runners:/app/conf/runners
      - ./script-server/scripts:/app/scripts
    ports:
      - 5000:5000
      - 5443:5443

But this one might give too much access leading to security issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bugy@agail@mmkk20158@ClarkeAC

        Issue actions

          How do you use this to run docker commands? · Issue #735 · bugy/script-server