I have below a Dockerfile for setting up a zookeeper, and for this I created a docker image.
FROM openjdk:8-jre-alpine # Install required packages RUN apk add --no-cache \ bash \ su-exec ENV ZOO_USER=zookeeper \ ZOO_CONF_DIR=/conf \ ZOO_DATA_DIR=/data \ ZOO_DATA_LOG_DIR=/datalog \ ZOO_PORT=2181 \ ZOO_TICK_TIME=2000 \ ZOO_INIT_LIMIT=5 \ ZOO_SYNC_LIMIT=2 # Add a user and make dirs RUN set -x \ && adduser -D "$ZOO_USER" \ && mkdir -p "$ZOO_DATA_LOG_DIR" "$ZOO_DATA_DIR" "$ZOO_CONF_DIR" \ && chown "$ZOO_USER:$ZOO_USER" "$ZOO_DATA_LOG_DIR" "$ZOO_DATA_DIR" "$ZOO_CONF_DIR" ARG GPG_KEY=C823E3E5B12AF29C67F81976F5CECB3CB5E9BD2D ARG DISTRO_NAME=zookeeper-3.4.9 # Download Apache Zookeeper, verify its PGP signature, untar and clean up RUN set -x \ && apk add --no-cache --virtual .build-deps \ gnupg \ && wget -q "http://www.apache.org/dist/zookeeper/$DISTRO_NAME/$DISTRO_NAME.tar.gz" \ && wget -q "http://www.apache.org/dist/zookeeper/$DISTRO_NAME/$DISTRO_NAME.tar.gz.asc" \ && export GNUPGHOME="$(mktemp -d)" \ && gpg --keyserver ha.pool.sks-keyservers.net --recv-key "$GPG_KEY" \ && gpg --batch --verify "$DISTRO_NAME.tar.gz.asc" "$DISTRO_NAME.tar.gz" \ && tar -xzf "$DISTRO_NAME.tar.gz" \ && mv "$DISTRO_NAME/conf/"* "$ZOO_CONF_DIR" \ && rm -r "$GNUPGHOME" "$DISTRO_NAME.tar.gz" "$DISTRO_NAME.tar.gz.asc" \ && apk del .build-deps WORKDIR $DISTRO_NAME VOLUME ["$ZOO_DATA_DIR", "$ZOO_DATA_LOG_DIR"] EXPOSE $ZOO_PORT 2888 3888 ENV PATH=$PATH:/$DISTRO_NAME/bin \ ZOOCFGDIR=$ZOO_CONF_DIR COPY docker-entrypoint.sh / ENTRYPOINT ["/docker-entrypoint.sh"] CMD ["zkServer.sh", "start-foreground"]
I will build it as follows:
root@duo4 :/home/david/zookeeper-docker
When I start the zookeeper instance, I get this error:
root@duo4 :/home/david/zookeeper-docker
What is wrong here? I have all my files inside the zookeeper-docker
directory. I also passed chmod +x
persmission to docker-entrypoint.sh
in my current directory.
The following is the contents of docker-entrypoint.sh
#!/bin/bash set -e # Allow the container to be started with `--user` if [ "$1" = 'zkServer.sh' -a "$(id -u)" = '0' ]; then chown -R "$ZOO_USER" "$ZOO_DATA_DIR" "$ZOO_DATA_LOG_DIR" exec su-exec "$ZOO_USER" "$0" " $@ " fi # Generate the config only if it doesn't exist if [ ! -f "$ZOO_CONF_DIR/zoo.cfg" ]; then CONFIG="$ZOO_CONF_DIR/zoo.cfg" echo "clientPort=$ZOO_PORT" >> "$CONFIG" echo "dataDir=$ZOO_DATA_DIR" >> "$CONFIG" echo "dataLogDir=$ZOO_DATA_LOG_DIR" >> "$CONFIG" echo "tickTime=$ZOO_TICK_TIME" >> "$CONFIG" echo "initLimit=$ZOO_INIT_LIMIT" >> "$CONFIG" echo "syncLimit=$ZOO_SYNC_LIMIT" >> "$CONFIG" for server in $ZOO_SERVERS; do echo "$server" >> "$CONFIG" done fi # Write myid only if it doesn't exist if [ ! -f "$ZOO_DATA_DIR/myid" ]; then echo "${ZOO_MY_ID:-1}" > "$ZOO_DATA_DIR/myid" fi exec " $@ "
Below is the result:
root@duo4 :/home/david/zookeeper-docker
source share