docker-webhook
docker-webhook copied to clipboard
How can I rebuild/restart another docker container from the webhook?
I have the webhook container running nicely along another container. I use docker compose to get them both running at the same time.
I would like to rebuild and restart the other container when the webhook is triggered.
Here is my script:
#!/usr/bin/env sh
GIT_REF=${1}
GIT_DIR=${2}
PUID=${3}
PGID=${4}
DOCKER_CONTAINER=${5}
USER=${6}
EMAIL=${7}
# log date
echo "[deploy] $(date):${6}(${7})"
# install git
if ! command -v git > /dev/null 2>&1; then
apk add --no-cache git
fi
# install openssh
if ! command -v ssh > /dev/null 2>&1; then
apk add --no-cache openssh
fi
if ! command -v docker > /dev/null 2>&1; then
apk add --no-cache docker
fi
if ! command -v docker-compose > /dev/null 2>&1; then
apk add --no-cache docker-compose
fi
git config --global --add safe.directory ${GIT_DIR}
git fetch --all
git checkout --force ${GIT_REF}
chown -R ${PUID}:${PGID} ${GIT_DIR}
docker-compose up --build ${DOCKER_CONTAINER} -d
#docker compose up --build ${DOCKER_CONTAINER} -d
I also added - /var/run/docker.sock:/var/run/docker.sock to the volumes of the webhook container in the compose file. I googled around and apparently I need that.
But the webhook image, when triggered, and tries to execute the docker compose command, can't seem to find the docker-compose.yaml. Of course it can't because I didn't mount it.. but is it required? How can I go about this rebuild/restart situation? Any ideas?