我正在尝试将 nodejs 应用程序容器化。该应用程序在我手动安装并运行 redis 的 Node 容器上运行良好,但是当我尝试使用我的 docker-compose 文件在容器中运行该应用程序时,出现错误:
“错误错误:Redis 连接到本地主机:6379 失败 - 连接 ECONNREFUSED 127.0.0.1:6379”。
我将在下面发布我的 docker-compose.yml 和 dockerfile 以及当我尝试执行 docker-compose up 时的控制台日志。
FROM node:8-jessie
WORKDIR /var/api-console
COPY package*.json ./
RUN npm install
COPY . . /var/api-console/
RUN apt-get update
RUN apt-get install python
EXPOSE 3000
version: '3'
services:
redis:
image: redis
ports:
- "6379:6379"
command:
redis-server
networks:
- webnet
app:
build: ./
volumes:
- ./:/var/api-console
ports:
- 3000:3000
command:
node app.js
networks:
- webnet
networks:
webnet:
AIDEVERSUSCATCH:api-console evan.dhillon$ docker-compose up
WARNING: The Docker Engine you're using is running in swarm mode.
Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.
To deploy your application across the swarm, use `docker stack deploy`.
Starting api-console_app_1 ... done
Starting api-console_redis_1 ... done
Attaching to api-console_app_1, api-console_redis_1
redis_1 | 1:C 04 Jun 2019 03:12:27.660 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 04 Jun 2019 03:12:27.660 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 04 Jun 2019 03:12:27.660 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1 | 1:M 04 Jun 2019 03:12:27.661 * Running mode=standalone, port=6379.
redis_1 | 1:M 04 Jun 2019 03:12:27.661 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1 | 1:M 04 Jun 2019 03:12:27.661 # Server initialized
redis_1 | 1:M 04 Jun 2019 03:12:27.661 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1 | 1:M 04 Jun 2019 03:12:27.661 * DB loaded from disk: 0.000 seconds
redis_1 | 1:M 04 Jun 2019 03:12:27.661 * Ready to accept connections
app_1 | Express server listening on port 3000
app_1 | Error Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
app_1 | Error AbortError: Redis connection lost and command aborted. It might have been processed.
app_1 | events.js:183
app_1 | throw er; // Unhandled 'error' event
app_1 | ^
app_1 |
app_1 | Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
app_1 | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
api-console_app_1 exited with code 1
最佳答案
您日志中的这一行解释了连接失败
Redis connection to localhost:6379 failed
Node 应用程序期望 redis 位于本地主机上,但事实并非如此。
您可以通过环境变量将redis容器的地址提供给您的 Node 应用。
同时在应用服务中添加一个depends_on,让它等待redis服务。修改后的 compose 文件如下
version: '3'
services:
redis:
image: redis
ports:
- "6379:6379"
command:
redis-server
networks:
- webnet
app:
build: ./
volumes:
- ./:/var/api-console
ports:
- 3000:3000
depends_on:
- redis
environment:
redis_server_addr: redis
#The dependent service address is set in environment variable which you can use in your app to connect
command:
node app.js
networks:
- webnet
networks:
关于node.js - Docker-compose 部署 redis 但 app.js 拒绝连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56436960/
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("
我使用的是Firefox版本36.0.1和Selenium-Webdrivergem版本2.45.0。我能够创建Firefox实例,但无法使用脚本继续进行进一步的操作无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055)错误。有人能帮帮我吗? 最佳答案 我遇到了同样的问题。降级到firefoxv33后一切正常。您可以找到旧版本here 关于ruby-无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055),我们在StackOverflow上找到一个类
我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie
当我在我的Rails应用程序根目录中运行rakedoc:app时,API文档是使用/doc/README_FOR_APP作为主页生成的。我想向该文件添加.rdoc扩展名,以便它在GitHub上正确呈现。更好的是,我想将它移动到应用程序根目录(/README.rdoc)。有没有办法通过修改包含的rake/rdoctask任务在我的Rakefile中执行此操作?是否有某个地方可以查找可以修改的主页文件的名称?还是我必须编写一个新的Rake任务?额外的问题:Rails应用程序的两个单独文件/README和/doc/README_FOR_APP背后的逻辑是什么?为什么不只有一个?
我可以在Azure网站上部署RubyonRails吗? 最佳答案 还没有。目前仅支持.NET和PHP。 关于ruby-on-rails-RubyonRails可以部署在Azure网站上吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/12964010/
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
前置步骤我们都操作完了,这篇开始介绍jenkins的集成。话不多说,看操作1、登录进入jenkins后会让你选择安装插件,选择第一个默认的就行。安装完成后设置账号密码,重新登录。2、配置JDK和Git都需要执行路径,所以需要先把执行路径找到,先进入服务器的docker容器,2.1JDK的路径root@69eef9ee86cf:/usr/bin#echo$JAVA_HOME/usr/local/openjdk-82.2Git的路径root@69eef9ee86cf:/#whichgit/usr/bin/git3、先配置JDK和Git。点击:ManageJenkins>>GlobalToolCon
我正在使用Postgres.app在OSX(10.8.3)上。我已经修改了我的PATH,以便应用程序的bin文件夹位于所有其他文件夹之前。Rammy:~phrogz$whichpg_config/Applications/Postgres.app/Contents/MacOS/bin/pg_config我已经安装了rvm并且可以毫无错误地安装pggem,但是当我需要它时我得到一个错误:Rammy:~phrogz$gem-v1.8.25Rammy:~phrogz$geminstallpgFetching:pg-0.15.1.gem(100%)Buildingnativeextension
深度学习部署:Windows安装pycocotools报错解决方法1.pycocotools库的简介2.pycocotools安装的坑3.解决办法更多Ai资讯:公主号AiCharm本系列是作者在跑一些深度学习实例时,遇到的各种各样的问题及解决办法,希望能够帮助到大家。ERROR:Commanderroredoutwithexitstatus1:'D:\Anaconda3\python.exe'-u-c'importsys,setuptools,tokenize;sys.argv[0]='"'"'C:\\Users\\46653\\AppData\\Local\\Temp\\pip-instal