diff --git a/README.md b/README.md index 4d922bb0..581db860 100644 --- a/README.md +++ b/README.md @@ -228,10 +228,6 @@ $ docker run -d \ * The `com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen` label - set this label on the docker-gen container to tell the docker-letsencrypt-nginx-proxy-companion container to use it as the docker-gen when it's split from nginx (separate containers). -* `DOCKER_PROVIDER` - Set this to change behavior on container ID retrieval. Optional. Current supported values: - * No value (empty, not set): no change in behavior. - * `ecs` [Amazon ECS using ECS_CONTAINER_METADATA_FILE environment variable](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-metadata.html) - * `DHPARAM_BITS` - Change the size of the Diffie-Hellman key generated by the container from the default value of 2048 bits. For example `-e DHPARAM_BITS=1024` to support some older clients like Java 6 and 7. #### Examples: diff --git a/app/entrypoint.sh b/app/entrypoint.sh index fd76c79f..3682957a 100755 --- a/app/entrypoint.sh +++ b/app/entrypoint.sh @@ -23,9 +23,11 @@ function check_docker_socket { function check_writable_directory { local dir="$1" - docker_api "/containers/${SELF_CID:-$(get_self_cid)}/json" | jq ".Mounts[].Destination" | grep -q "^\"$dir\"$" - if [[ $? -ne 0 ]]; then - echo "Warning: '$dir' does not appear to be a mounted volume." + if [[ $(get_self_cid) ]]; then + docker_api "/containers/$(get_self_cid)/json" | jq ".Mounts[].Destination" | grep -q "^\"$dir\"$" + [[ $? -ne 0 ]] && echo "Warning: '$dir' does not appear to be a mounted volume." + else + echo "Warning: can't check if '$dir' is a mounted volume without self container ID." fi if [[ ! -d "$dir" ]]; then echo "Error: can't access to '$dir' directory !" >&2 @@ -139,12 +141,6 @@ if [[ "$*" == "/bin/bash /app/start.sh" ]]; then exit 1 fi check_docker_socket - if [[ -z "$(get_self_cid)" ]]; then - echo "Error: can't get my container ID !" >&2 - exit 1 - else - export SELF_CID="$(get_self_cid)" - fi if [[ -z "$(get_nginx_proxy_container)" ]]; then echo "Error: can't get nginx-proxy container ID !" >&2 echo "Check that you are doing one of the following :" >&2 diff --git a/app/functions.sh b/app/functions.sh index 0128540a..8d4957a6 100644 --- a/app/functions.sh +++ b/app/functions.sh @@ -60,22 +60,15 @@ function check_cert_min_validity { } function get_self_cid { - DOCKER_PROVIDER=${DOCKER_PROVIDER:-docker} - - case "${DOCKER_PROVIDER}" in - ecs|ECS) - # AWS ECS. Enabled in /etc/ecs/ecs.config (http://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-metadata.html) - if [[ -n "${ECS_CONTAINER_METADATA_FILE:-}" ]]; then - grep ContainerID "${ECS_CONTAINER_METADATA_FILE}" | sed 's/.*: "\(.*\)",/\1/g' - else - echo "${DOCKER_PROVIDER} specified as 'ecs' but not available. See: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-metadata.html" >&2 - exit 1 - fi - ;; - *) - sed -nE 's/^.+docker[\/-]([a-f0-9]{64}).*/\1/p' /proc/self/cgroup | head -n 1 - ;; - esac + local self_cid + self_cid="$(basename "$(cat /proc/1/cpuset)")" + if [[ -n "$self_cid" ]]; then + echo "$self_cid" + return 0 + else + echo "$(date "+%Y/%m/%d %T"), Error: can't get my container ID !" >&2 + return 1 + fi } ## Docker API @@ -162,8 +155,8 @@ function get_nginx_proxy_container { if [[ -n "${NGINX_PROXY_CONTAINER:-}" ]]; then nginx_cid="$NGINX_PROXY_CONTAINER" # ... else try to get the container ID with the volumes_from method. - else - volumes_from=$(docker_api "/containers/${SELF_CID:-$(get_self_cid)}/json" | jq -r '.HostConfig.VolumesFrom[]' 2>/dev/null) + elif [[ $(get_self_cid) ]]; then + volumes_from=$(docker_api "/containers/$(get_self_cid)/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