nodejs,redis,npm和docker-compose设置 [英] nodejs, redis, npm and docker-compose setup
问题描述
我想使用docker和docker-compose安装nodejs,npm,redis和memcached.但是我并没有只安装Redis(通过文档)./p>
我接下来做了:1安装docker,docker-compose2创建文件夹:〜/app目录中的3个创建了Dockerfile,docker-compose.yml,app.py,requirements.txt
requirements.txt:
redis
app.py :
从烧瓶导入烧瓶的 从redis导入Redisapp = Flask(__ name__)redis = Redis(主机='redis',端口= 6379)@ app.route('/')def hello():count = redis.incr('hits')返回"Hello World!我见过{}次.\ n'.format(count)如果__name__ =="__main__":app.run(host ="0.0.0.0",debug = True)
Dockerfile :
FROM重做:3.2稳定添加 ./应用程序WORKDIR/appRUN pip install -r requirements.txtCMD ["app.py"]
docker-compose.yml
版本:"2"服务:网络:建造: .端口:-"5000:5000"数量:- .:/代码Redis:图片:"redis:alpine"
运行compose docker-compose up -d
并出现错误
无法通过http + docker://localunixsocket连接到Docker守护程序-它在运行吗?如果它位于非标准位置,请指定URL使用DOCKER_HOST环境变量.
出什么问题了?如何设置至少一个Redis?
PS (如果您知道如何使用docker-compose nodejs npm和memcached进行安装)我将很感激
在命令前添加 sudo
怎么样?
I would like install nodejs, npm, redis and memcached with docker and docker-compose. But i did not install only redis (by document).
I did next: 1 install docker, docker-compose 2 create folder: ~/app 3 in catalog was create Dockerfile, docker-compose.yml, app.py,requirements.txt
requirements.txt:
redis
app.py:
from flask import Flask
from redis import Redis
app = Flask(__name__)
redis = Redis(host='redis', port=6379)
@app.route('/')
def hello():
count = redis.incr('hits')
return 'Hello World! I have been seen {} times.\n'.format(count)
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
Dockerfile:
FROM redis:3.2-stable
ADD . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD [ "app.py"]
docker-compose.yml
version: '2'
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
redis:
image: "redis:alpine"
run compose docker-compose up -d
and have error
Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running? If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
What is problem? How setup at least one redis ?
P.S. If you know how install with docker-compose nodejs npm and memcached I will be grateful
How about add sudo
before your command?
这篇关于nodejs,redis,npm和docker-compose设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!