Running / stopping other containers
kachkaev opened this issue · 3 comments
Thanks a lot for this image @almir!
I'm just starting to play with webhook
and would like to run it on a server that has several other docker containers. My goal is to trigger a pull of a webapp's image and then to restart it. So the bash script would be something like:
#redeploy.sh
cd /path/to/webapp
docker-compose pull
docker-compose up -d
The fact that webhook
runs in a container means that there won't be any access to such actions by default, as these are supposed to be executed only on the host. I've heard of docker-in-docker
and suspect that it might be useful here, but still unsure how to implement what I'm up to unless running webhook
on the host directly. Seems like I'm not the only one here.
Could you please extend your docs with a simple example of how to control host dockers inside a dockerised webhook
(if possible at all)?
The standard way is to mount the docker socket into the container. Just add -v /var/run/docker.sock:/var/run/docker.sock
to the docker run
command.
Of course the container needs to have the docker client binary or equivalent.
@kachkaev Sorry for late response, been really busy lately.
Basically, the answer from @nafg covers what you need.
In short, you need to create new webhook image using the process described in ReadMe, that will also have docker client, docker compose, etc. installed.
While running the docker container from that new image you need to provide it with access to all files and directories where the deploy scripts are located, and also the ones the deploy script refers to, for example:
docker run -d -p 9000:9000 --name=webhook \
-v /path/to/hooks/on/host:/etc/webhook \
-v /path/to/scripts/on/host:/opt/scripts \
-v /path/to/app/on/host:/opt/app \
-v /var/run/docker.sock:/var/run/docker.sock \
kachkaev/webhook -verbose -hooks=/etc/webhook/hooks.json -hotreload
Example webhook Dockerfile
containing docker client and docker compose:
FROM almir/webhook
RUN apk --update --upgrade add docker curl bash python && \
curl -L -o /tmp/get-pip.py https://bootstrap.pypa.io/get-pip.py && \
python /tmp/get-pip.py && \
pip install docker-compose && \
rm -f /tmp/get-pip.py && \
rm -rf /var/cache/apk/*
Just found this issue and it looks like it isn't working anymore with the script above.
I made a quick docker push of an working image with current dependencies (for the case if someone has the same problem)
More information on lwlook/webhook