gbraad-devenv / fedora-codesandbox

Fedora-based codesandbox
https://gbraad.nl/devenv
0 stars 0 forks source link

Update docker check #1

Open gbraad opened 1 year ago

gbraad commented 1 year ago

Check if the container already exists

https://github.com/gbraad/devenv-csb/blob/2c8462ed0f3b2e7eeab52f6f3830af0671b52bb9/.codesandbox/tasks.json#LL6C18-L6C319

... and if so, (re)start it.

sudo docker exec tailscaled tailscale up --hostname=devenv-`cat /etc/hostname` --accept-dns=false --advertise-exit-node
gbraad commented 1 year ago
"[ ! "$(docker ps -a | grep tailscaled)" ] && docker run -d --name=tailscaled -v /var/run/tailscale/:/var/run/tailscale/ -v /var/lib:/var/lib -v /dev/net/tun:/dev/net/tun --network=host --cap-add=NET_ADMIN --cap-add=NET_RAW --cap-add=SYS_MODULE --env TS_SOCKET=/var/run/tailscale/tailscale.sock --env TS_AUTHKEY=${TS_AUTHKEY} tailscale/tailscale"

Better to move this to scripts/start-tailscale

if [ ! "$(docker ps -a -q -f name=tailscaled)" ]; then
    if [ "$(docker ps -aq -f status=exited -f name=tailscaled)" ]; then
        # cleanup
        docker rm tailscaled
    fi
    docker run -d --name=tailscaled \
           -v /var/run/tailscale/:/var/run/tailscale/ \
           -v /var/lib:/var/lib \
           -v /dev/net/tun:/dev/net/tun \
           --network=host \
           --cap-add=NET_ADMIN \
           --cap-add=NET_RAW \
           --cap-add=SYS_MODULE \
           --env TS_SOCKET=/var/run/tailscale/tailscale.sock \
           --env TS_AUTHKEY=${TS_AUTHKEY}
       tailscale/tailscale
fi