thelebster / example-mosquitto-simple-auth-docker

Configure Mosquitto MQTT broker to require client authentication using a valid username and password.
52 stars 35 forks source link

Trying to run image on Caprover getting ./docker-entrypoint.sh: line 2: : not found #5

Open abbjetmus opened 2 years ago

abbjetmus commented 2 years ago

I'm trying to run this setup on Caprover, you don't run docker-compose files there but you can run Dockerfile. My Dockerfile looks like this, so I'm not using the info from docker-compose at all:

// Dockerfile

FROM eclipse-mosquitto:latest

COPY config/mosquitto.conf /mosquitto/config/mosquitto.conf
COPY docker-entrypoint.sh /

ENTRYPOINT ["sh", "./docker-entrypoint.sh"]

CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"]

Running this dockerfile I'm getting complaints from the docker-entrypoint.sh file accordingly on Caprover logs:

// logs

2022-04-29T20:29:33.226580837Z ./docker-entrypoint.sh: line 2:
: not found
2022-04-29T20:29:33.226637663Z ./docker-entrypoint.sh: set: line 3: illegal option -
2022-04-29T20:29:36.720567213Z ./docker-entrypoint.sh: line 2:
: not found
2022-04-29T20:29:36.720658856Z ./docker-entrypoint.sh: set: line 3: illegal option -
2022-04-29T20:29:38.024713443Z ./docker-entrypoint.sh: line 2:
: not found
2022-04-29T20:29:38.024821383Z ./docker-entrypoint.sh: set: line 3: illegal option -

Any ideas why that is?

// docker-entrypoint.sh

#!/bin/ash

set -e

# Fix write permissions for mosquitto directories
chown --no-dereference --recursive mosquitto /mosquitto/log
chown --no-dereference --recursive mosquitto /mosquitto/data

mkdir -p /var/run/mosquitto \
  && chown --no-dereference --recursive mosquitto /var/run/mosquitto

# Adjust configuration to support Mosquitto 2.x
if [ $(echo $VERSION | cut -d "." -f1) -gt 1 ]; then
  # Use 'listener' instead of 'port'
  sed -i "s/port 1883/listener 1883/g" /mosquitto/config/mosquitto.conf
fi

if ( [ -z "${MOSQUITTO_USERNAME}" ] || [ -z "${MOSQUITTO_PASSWORD}" ] ); then
  echo "MOSQUITTO_USERNAME or MOSQUITTO_PASSWORD not defined"
  exit 1
fi

# create mosquitto passwordfile
touch passwordfile
mosquitto_passwd -b passwordfile $MOSQUITTO_USERNAME $MOSQUITTO_PASSWORD

exec "$@"
thelebster commented 2 years ago

I can't say anything regarding your specific case, but I have added instructions how to run service with just a Docker. Let me know if that make sense.