Closed
Description
Hi,
I am trying to get letsencrypt-nginx-proxy-companion to work with the latest docker swarm/compose
Unfortunately volumes_from can not be used with stacks
Compose file contains unsupported options:
volumes_from: To share a volume between services, define it using the top-level `volumes` option and reference it from each service that shares it using the service-level `volumes` option.
And it doesn't look like NGINX_PROXY_CONTAINER=**** can be used, as container_name cant be set either
Ignoring deprecated options:
container_name: Setting the container name is not supported.
I am working on a way to dynamically look up the containerId from a label
Set up the containers like this
nginx:
image: jwilder/nginx-proxy
labels:
- "NGINX_PROXY_SWARM_CONTAINER=true"
letsencrypt-nginx-proxy-companion:
image: ${DOCKER_REGISTRY}/hdtl-proxy-letsencrypt
environment:
- NGINX_PROXY_SWARM_CONTAINER=true
And then lookup the containerId in entrypoint.sh like this
function get_nginx_proxy_cid {
# Look for a NGINX_VERSION environment variable in containers that we have mount volumes from.
local volumes_from=$(docker_api "/containers/$CONTAINER_ID/json" | jq -r '.HostConfig.VolumesFrom[]' 2>/dev/null)
for cid in $volumes_from; do
cid=${cid%:*} # Remove leading :ro or :rw set by remote docker-compose (thx anoopr)
if [[ $(docker_api "/containers/$cid/json" | jq -r '.Config.Env[]' | egrep -c '^NGINX_VERSION=') = "1" ]];then
export NGINX_PROXY_CONTAINER=$cid
break
fi
done
# TEST: curl --unix-socket /var/run/docker.sock -G -XGET "http://localhost/containers/json" -d 'all=0&filters=%7B%22label%22%3A%5B%22NGINX_PROXY_SWARM_CONTAINER%22%5D%7D' | jq -r ".[] | .Id"
echo "checking for swarm mode ... "
if [[ -n "${NGINX_PROXY_SWARM_CONTAINER:-}" ]]; then
echo "... swarm mode detected"
echo ""
echo "containers found:"
docker_api "/containers/json?all=0&filters=%7B%22label%22%3A%5B%22NGINX_PROXY_SWARM_CONTAINER%22%5D%7D" | jq -r ".[] | .Names[0]"
echo "---------------------------"
echo ""
nginxswarmcontainerid=$(docker_api "/containers/json?all=0&filters=%7B%22label%22%3A%5B%22NGINX_PROXY_SWARM_CONTAINER%22%5D%7D" | jq -r ".[] | .Id")
echo "nginxswarmcontainerid: [$nginxswarmcontainerid]"
echo "---------------------------"
echo ""
export NGINX_PROXY_CONTAINER=$nginxswarmcontainerid
fi
if [[ -z "${NGINX_PROXY_CONTAINER:-}" ]]; then
echo "Error: can't get nginx-proxy container id !" >&2
echo "Check that you use the --volumes-from option to mount volumes from the nginx-proxy." >&2
exit 1
fi
}
This seems to work:
checking for swarm mode ...
... swarm mode detected
containers found:
/proxy_nginx.1.bh6cty5dz9nlxvmw0znnmrep1
---------------------------
nginxswarmcontainerid: [06883fe069376656c3943b8ce2ba3710d0b174a7df0ab42bbafb55d641259317]
---------------------------
Sleep for 3600s
2017/01/01 20:52:55 Generated '/app/letsencrypt_service_data' from 9 containers
2017/01/01 20:52:55 Running '/app/update_certs'
2017/01/01 20:52:55 Watching docker events
2017/01/01 20:52:55 Contents of /app/letsencrypt_service_data did not change. Skipping notification '/app/update_certs'
However then i get hit by #144, so can't confirm if this fully works
Is there a better way to do this?
Metadata
Metadata
Assignees
Labels
No labels