just wanted to add that I also recently ran into this issue when using Azure Container Instances with a Azure Files mounted into the system. Inotify also fails to see any changes on the Azure Files mount, I guess since it's using CIFS.
I stumbled upon a useful tool that can also use polling
instead of inotify
.
It's called fswatch
.
https://emcrisostomo.github.io/fswatch/
I had to create my own package for the Alpine based container in question, but it wasn't too difficult using the instructions on Alpine's site.
https://wiki.alpinelinux.org/wiki/Creating_an_Alpine_package
Here's my APKBUILD
if anyone finds it helpful (shamelessly based on the sample provided by Alpine! :) )
# Contributor:
# Maintainer:
pkgname=fswatch
pkgver=1.17.1
pkgrel=0
pkgdesc="A cross-platform file change monitor with multiple backends"
url="https://emcrisostomo.github.io/fswatch/"
arch="all"
license="GPL"
depends=""
depends_dev="alpine-sdk"
makedepends="$depends_dev"
install=""
subpackages="$pkgname-doc"
source="https://github.com/emcrisostomo/$pkgname/releases/download/$pkgver/$pkgname-$pkgver.tar.gz"
builddir="$srcdir/$pkgname-$pkgver"
prepare() {
default_prepare
# this function can be omitted if no extra steps are needed
}
build() {
./configure --prefix=/usr \
--sysconfdir=/etc \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--localstatedir=/var \
--disable-wxwidgets \
--disable-qt
make
}
check() {
make check
}
package() {
make DESTDIR="$pkgdir" install
}
sha512sums="c38e341c567f5f16bfa64b72fc48bba5e93873d8572522e670e6f320bbc2122f fswatch-1.17.1.tar.gz"
I used a multi-stage Dockerfile
and then copied the resulting package into the target container. I had to use the --allow-untrusted
flag to do the install.
apk add --allow-untrusted /tmp/fswatch-1.17.1-r0.apk
Here's the relavent section of the Dockerfile
## ==========
## FSWatcher Builder
# IMPORTANT: Build this package on the same Alpine version used by the target container
FROM ${ALPINE_CONTAINER}:${ALPINE_VERSION} AS fswatch
COPY /scripts/fswatch.apkbuild /tmp/APKBUILD
USER root
WORKDIR /app
RUN apk upgrade --update-cache --available && apk add alpine-sdk sudo && rm -rf /var/cache/apk/*; \
adduser -D -h /home/build build; \
addgroup build abuild; \
mkdir -p /var/cache/distfiles; \
chmod a+w /var/cache/distfiles; \
chgrp abuild /var/cache/distfiles; \
chmod g+w /var/cache/distfiles; \
abuild-keygen -a -i -n
USER build
WORKDIR /home/build
RUN abuild-keygen -a -n; \
mkdir fswatch; \
cd fswatch; \
cp /tmp/APKBUILD ./; \
dos2unix ./APKBUILD; \
abuild checksum; \
abuild -r
UPDATE: Here's my entrypoint.sh
as well, where I run fswatch
(I had to use a bash
shebang on debian based system...YMMV.)
#!/bin/sh
set -e
{ /usr/bin/fswatch -0 -o -r -m poll_monitor /etc/nginx/ssl | while read -d "" event;do echo "$(date -Ins) Event Fired: ${event}";/opt/reload.sh;done; } &
exec "$@"
And the reload.sh
script:
#!/bin/sh
set -e
/usr/sbin/nginx -s reload && echo "nginx reloaded"
Hope those are useful for someone in the same boat!