diff --git a/Dockerfile b/Dockerfile
index afdc46f7d39e6cfe87a483aac8fb3ac92072b80c..6e8ec04e8f0159ed2e6ff0018b008d779d80b8f1 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -9,6 +9,7 @@ ENV ALLOW_RESTARTS=0 \
     COMMIT=0 \
     CONFIGS=0 \
     CONTAINERS=0 \
+    DISABLE_IPV6=0 \
     DISTRIBUTION=0 \
     EVENTS=1 \
     EXEC=0 \
@@ -30,4 +31,5 @@ ENV ALLOW_RESTARTS=0 \
     TASKS=0 \
     VERSION=1 \
     VOLUMES=0
-COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
+COPY docker-entrypoint.sh /usr/local/bin/
+COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg.template
diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
new file mode 100755
index 0000000000000000000000000000000000000000..c328d3af430d24070258f05d30727805ef075fd7
--- /dev/null
+++ b/docker-entrypoint.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+set -e
+
+# Normalize the input for DISABLE_IPV6 to lowercase
+DISABLE_IPV6_LOWER=$(echo "$DISABLE_IPV6" | tr '[:upper:]' '[:lower:]')
+
+# Check for different representations of 'true' and set BIND_CONFIG
+case "$DISABLE_IPV6_LOWER" in
+    1|true|yes)
+        BIND_CONFIG=":2375"
+        ;;
+    *)
+        BIND_CONFIG="[::]:2375 v4v6"
+        ;;
+esac
+
+# Process the HAProxy configuration template using sed
+sed "s/\${BIND_CONFIG}/$BIND_CONFIG/g" /usr/local/etc/haproxy/haproxy.cfg.template > /usr/local/etc/haproxy/haproxy.cfg
+
+# first arg is `-f` or `--some-option`
+if [ "${1#-}" != "$1" ]; then
+	set -- haproxy "$@"
+fi
+
+if [ "$1" = 'haproxy' ]; then
+	shift # "haproxy"
+	# if the user wants "haproxy", let's add a couple useful flags
+	#   -W  -- "master-worker mode" (similar to the old "haproxy-systemd-wrapper"; allows for reload via "SIGUSR2")
+	#   -db -- disables background mode
+	set -- haproxy -W -db "$@"
+fi
+
+exec "$@"
diff --git a/haproxy.cfg b/haproxy.cfg
index c87c8d837b60b39b003a6efb811b0d99c82fb3b4..43e3526cd15fa68102fe4f2f3f276ca3d74e22be 100644
--- a/haproxy.cfg
+++ b/haproxy.cfg
@@ -44,7 +44,7 @@ backend docker-events
     timeout server 0
 
 frontend dockerfrontend
-    bind :::2375 v4v6
+    bind ${BIND_CONFIG}
     http-request deny unless METH_GET || { env(POST) -m bool }
     http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/containers/[a-zA-Z0-9_.-]+/((stop)|(restart)|(kill)) } { env(ALLOW_RESTARTS) -m bool }
     http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/containers/[a-zA-Z0-9_.-]+/start } { env(ALLOW_START) -m bool }