0

I have 2 containers: a Redis container and a container for a Golang application. My Golang application is trying to perform Redis Mass Insertion (https://redis.io/topics/mass-insert) by executing a bash script with the command cat ${FILE}| redis-cli --pipe -h ${HOST}.

However, redis-cli is not found within the PATH system variable and it is not a built-in shell command in the Golang application service.

Hence, I get an exit status 127, which means the given command in not found. I would like to know how I would be able to execute the bash script without redis-cli command in the Golang application service.

6
  • Need more info. Does the command need to be run from within the container? or will you run the command from the docker host server? Are the two containers on the same host server? Commented Apr 27, 2018 at 16:44
  • Yes, the command redis-cli needs to be run from within the same container Commented Apr 27, 2018 at 16:46
  • Yes, the two containers are on the same host server (my localhost) Commented Apr 27, 2018 at 16:47
  • Can the command be run from the host server instead of from within the golang app container? Commented Apr 27, 2018 at 16:51
  • This could definitely be done, but I would like to know if the latter would be possible. Commented Apr 27, 2018 at 16:57

2 Answers 2

2

It is possible to run the command from within the application container only if you rebuild your go application image and install the redis cli tools. Example using an ubuntu based image (add this to your Dockerfile): RUN apt update; apt -y install redis-tools If you are using docker compose, you can talk to your redis server using the name specified in your docker compose file.

cat ${FILE}| redis-cli --pipe -h redis-server

Assuming you name your redis container as shown in this sample

version: '3'
services:
  redis-server:
    image: xxx
[...]

Alternatively, if you want to run the command from the host server, you'll have to make sure you are forwarding the redis port from the redis container, then you can use:

docker exec {containerId} 'cat {FILE}' | redis-cli --pipe -h localhost:{REDIS_CONTAINER_PORT}`
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Could you tell me how to install redis on an alpine image. I am using golang:1.10.1-alpine3.7. I tried RUN apk add --no-cache redis, but i still get redis-cli command not found
1

When you build your application docker image make sure you have install redis client and bash, Depending on base image you may use apk add bash, or apt-get install -y bash. For instance if you are using alpine base image your Docker file might look like:

Dockerfile

FROM golang:1.10.1-alpine3.7

RUN apk add --no-cache ca-certificates bash redis
RUN apk add --update tzdata curl && rm -rf /var/cache/apk/*
ADD myapp /
CMD ["myapp"]

4 Comments

Hey! I think RUN apk add -y redis-tools gives apk: unrecognized option: y
Sorry but that fails too with ERROR: unsatisfiable constraints: redis-tools (missing): required by: world[redis-tools]
I am using the image golang:1.10.1-alpine3.7.
pkgs.alpinelinux.org/… looks like alpine has packaged called redis,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.