Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redis:4.0.8-alpine - Unable to configure Docker Redis cluster from Ansible playbook, Ruby error? #133

Closed
MelisaLang opened this issue Mar 16, 2018 · 2 comments

Comments

@MelisaLang
Copy link

MelisaLang commented Mar 16, 2018

There are 6 VMs running Docker Redis 4.0.8 containers. We modified the Dockerfile to install ruby and also to include the redis-trib.rb file (see below). We use Ansible scripts to deploy the images to each of the clusters; however, when we run our Ansible playbook to configure the cluster, this task fails:

- name: "redis 4.0.8 lru cluster: create"
  run_once: true
  when: count_cluster_conf_lines.stdout == "2"
  shell: |
    yes yes | docker exec -i redis-4.0.8-lru-6379 /usr/local/bin/redis-trib.rb create --replicas 1 172.24.172.254:6379 172.24.172.252:6379 172.24.172.250:6379 172.24.172.243:6379 172.24.172.241:6379 172.24.172.231:6379

It fails with the following error:

{
	"changed": true,
	"cmd": "yes yes | docker exec -i redis-4.0.8-lru-6379 /usr/local/bin/redis-trib.rb create --replicas 1 172.24.172.254:6379 172.24.172.252:6379 172.24.172.250:6379 172.24.172.243:6379 172.24.172.241:6379 172.24.172.231:6379",
	"delta": "0:00:00.076751",
	"end": "2018-03-16 14:57:45.302881",
	"msg": "non-zero return code",
	"rc": 1,
	"start": "2018-03-16 14:57:45.226130",
	"stderr": "env: can't execute 'ruby\r': Not a directory\nread unix @->/var/run/docker.sock: read: connection reset by peer\nyes: standard output: Broken pipe\nyes: write error",
	"stderr_lines": [
		"env: can't execute 'ruby",
		"': Not a directory",
		"read unix @->/var/run/docker.sock: read: connection reset by peer",
		"yes: standard output: Broken pipe",
		"yes: write error"
	],
	"stdout": "",
	"stdout_lines": [
	]
}

############## Dockerfile for the base image, there is another file that is FROM this file which includes the redis.conf file and that is used to build the image that is actually deployed #######################

# This is a base image from which other Dockerfiles inherit.
FROM alpine:3.7
MAINTAINER xxxxxxxxxxxxxxxxxxxxxxx

# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
# RUN addgroup -S redis && adduser -S -G redis redis
RUN addgroup -g 4640 -S redis && adduser -u 4640 -S -G redis redis

# grab su-exec for easy step-down from root
RUN apk add --no-cache 'su-exec>=0.2'

ENV REDIS_VERSION 4.0.8
ENV REDIS_DOWNLOAD_URL http://download.redis.io/releases/redis-4.0.8.tar.gz
ENV REDIS_DOWNLOAD_SHA ff0c38b8c156319249fec61e5018cf5b5fe63a65b61690bec798f4c998c232ad

# for redis-sentinel see: http://redis.io/topics/sentinel
RUN set -ex; \
        \
        apk add --no-cache --virtual .build-deps \
                coreutils \
                gcc \
                linux-headers \
                make \
                musl-dev \
        ; \
        \
        wget -O redis.tar.gz "$REDIS_DOWNLOAD_URL"; \
        echo "$REDIS_DOWNLOAD_SHA *redis.tar.gz" | sha256sum -c -; \
        mkdir -p /usr/src/redis; \
        tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1; \
        rm redis.tar.gz; \
        \
# disable Redis protected mode [1] as it is unnecessary in context of Docker
# (ports are not automatically exposed when running inside Docker, but rather explicitly by specifying -p / -P)
# [1]: https://github.com/antirez/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da
        grep -q '^#define CONFIG_DEFAULT_PROTECTED_MODE 1$' /usr/src/redis/src/server.h; \
        sed -ri 's!^(#define CONFIG_DEFAULT_PROTECTED_MODE) 1$!\1 0!' /usr/src/redis/src/server.h; \
        grep -q '^#define CONFIG_DEFAULT_PROTECTED_MODE 0$' /usr/src/redis/src/server.h; \
# for future reference, we modify this directly in the source instead of just supplying a default configuration flag because apparently "if you specify any argument to redis-server, [it assumes] you are going to specify everything"
# see also https://github.com/docker-library/redis/issues/4#issuecomment-50780840
# (more exactly, this makes sure the default behavior of "save on SIGTERM" stays functional by default)
        \
        make -C /usr/src/redis -j "$(nproc)"; \
        make -C /usr/src/redis install; \
        rm -r /usr/src/redis; \
        \
        runDeps="$( \
                scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
                        | tr ',' '\n' \
                        | sort -u \
                        | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
        )"; \
        apk add --virtual .redis-rundeps $runDeps; \
        apk del .build-deps; \
		\
		apk add --update \
			ca-certificates \
			ruby \
		; \
		rm -fr /usr/share/ri; \
		gem install --no-ri --no-rdoc redis; \
		\
        redis-server --version

RUN chown redis:redis /usr/bin/ruby
RUN chmod a+x /usr/bin/ruby
ENV PATH /usr/bin/ruby:$PATH

RUN mkdir /data && chown redis:redis /data
VOLUME /data
WORKDIR /data

COPY bin/* /usr/local/bin/
RUN chmod a+x /usr/local/bin/redis-trib.rb
RUN chmod a+x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]

EXPOSE 6379

# run redis as a non-privileged user
USER redis

# This image does not contain a redis.conf configuration file
# Derived images must provide a redis.conf via COPY in their Dockerfile for this CMD to work
CMD ["redis-server","/usr/local/etc/redis.conf"]
@yosifkit
Copy link
Contributor

env: can't execute 'ruby\r':

Remove windows line endings from redis-trib.rb. (https://help.github.com/articles/dealing-with-line-endings/)

@yosifkit
Copy link
Contributor

In the future, it'd be better to post questions like this in the Docker Community Forums, the Docker Community Slack, or Stack Overflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants