doutang2017 2018-04-27 16:28
浏览 1778


I have 2 containers: a Redis container and a container for a Golang application. My Golang application is trying to perform Redis Mass Insertion ( 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.

  • 写回答

2条回答 默认 最新

  • douaonong7807 2018-04-27 17:39

    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'
        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}`
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥100 关于注册表摄像头和麦克风的问题
  • ¥30 代码本地运行正常,但是TOMCAT部署时闪退
  • ¥15 关于#python#的问题
  • ¥15 主机可以ping通路由器但是连不上网怎么办
  • ¥15 数据库一张以时间排好序的表中,找出多次相邻的那些行
  • ¥50 关于DynamoRIO处理多线程程序时候的问题
  • ¥15 kubeadm部署k8s出错
  • ¥15 Abaqus打不开cae文件怎么办?
  • ¥20 双系统开机引导中windows系统消失问题?
  • ¥15 小程序准备上线,软件开发公司需要提供哪些资料给甲方