VM/LXC Initialisierungsscript Docker und Portainer

km65

New Member
Jul 9, 2023
1
0
1
Hallo zusammen,

ich würde mir gern ein initiales Startup Script erstellen, welches ich in einem LXC Temlpate ergänze, um einen fertigen in Portainer gejointen Docker LXC erhalte.
Soweit so gut... nun stecke ich jedoch bei der Nutzung der Portainer API fest.

Bis dahin läuft alles wunderbar, nur das "add environment" über die API klappt nicht. Vielleicht stelle ich mich auch einfach zu doof an den richtigen Request über Curl zusammenzubauen.

Kann hier ggf. jemand einen hilfreichen Tipp da lassen?

Lieben Dank schonmal!

Bash:
#!/bin/bash

FILE=/etc/initalized
if [ -f "$FILE" ]; then
    echo "already initialized"
else
    echo "update and initializing curl, docker and portainer..."
    touch /etc/initalized
    apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y curl && \
    curl -fsSL https://get.docker.com -o get-docker.sh && \
    chmod +x get-docker.sh && \
    sh ./get-docker.sh && \
    docker run -d \
        -p 9001:9001 \
        --name portainer_agent \
        --restart=always \
        -v /var/run/docker.sock:/var/run/docker.sock \
        -v /var/lib/docker/volumes:/var/lib/docker/volumes \
        portainer/agent:2.18.4


    currip="$(ip a s eth0 | grep -E -o 'inet [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | cut -d' ' -f2)"
    currhostname="$(hostname)"


    P_USER="portaineruser"
    P_PASS="portainerpassword"
    P_URL="http://192.168.1.217:8000"
    T="access token from myAcount"

    #Test getting token by API
    #P_TOKEN=$(curl -s -X POST -H "Content-Type: application/json;charset=UTF-8" -d "{\"username\":\"$P_USER\",\"password\":\"$P_PASS\"}" "$P_URL/api/auth")
    #T=$(echo $P_TOKEN | awk -F '"' '{print $4}')


    UPDATE=$(curl -s \
    "$P_URL/api/endpoints" \
    -X PUT \
    -H "Authorization: Bearer $T" \
    -H "Content-Type: application/json;charset=UTF-8" \
                -d "{\"Name\":\"$currhostname\",\"URL\":\"$currip\",\"EndpointCreationType\":1}"
            )

    if [ -z ${UPDATE+x} ]; then
      echo "Result: failure  to update"
      exit 1
    else
      echo "Result: env successfully added"
      exit 0
    fi

fi
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!