运行2个服务 [英] Running 2 services

查看:257
本文介绍了运行2个服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在根据neo4j数据库中心的图像,为github的Linkurious项目构建一个映像。 neo图像自动运行端口7474上的服务器,我的镜像在端口8000上运行。



当我运行我的图像时我发布两个端口(可以用EXPOSE吗? ):

  docker run -d --publish = 7474:7474 --publish = 8000:8000 linkurious 

但只有我的服务器似乎运行。如果我点击 http:// [ip]:7474 / 我什么也没收。有没有什么特别之处,以确保他们都运行?



*编辑我*



这里是我的Dockerfile:

  FROM neo4j / neo4j:最新
RUN apt-get -y更新
运行apt-get install -y git
运行apt-get install -y npm
运行apt-get install -y nodejs-legacy
运行git clone git:// github.com/Linkurious/linkurious.js.git
运行cd linkurious.js&& npm安装&& npm运行build
CMD cd linkurious.js&& npm开始

*编辑II *



可能有助于解释我的困扰,我已经要求






确保ip是正确的( $(docker-machine ip default))。






如果您正在使用虚拟机(意思是您不直接在Linux主机上使用docker,而是在Linux上VM与 VirtualBox )),请确保映射的端口7474和8000是从主机转发到VM

  VBoxManage controlvm boot2docker-vm natpf1name,tcp ,, 7474,,7474
VBoxManage controlvm boot2docker-vm natpf1name,tcp ,, 8000,,8000






在OP的情况下,这是使用neo4j:请参见 Neo4j with Docker ,基于 neo4j / neo4j / 图像和其Dockerfile

  ENTRYPOINT [/docker-entrypoint.sh] 
CMD [neo4j]

它不是用于安装另一个服务(如nodejs),其中 CMD cd linkurious.js&& npm开始将完全覆盖 neo4j 基本图像 CMD (含义 neo4j 永远不会启动)



它的意图是自己运行:

 #与终端互动
docker run -i -t --rm --name neo4j -v $ HOME / neo4j-data:/ data -p 8474:7474 neo4j / neo4j

#作为后台运行的守护进程
docker run -d --name neo4j -v $ HOME / neo4j-data:/ data -p 8474:7474 neo4j / neo4j

然后再使用另一个图片,一个链接neo4j:neo4j 指令。


I'm building an image for github's Linkurious project, based on an image already in the hub for the neo4j database. the neo image automatically runs the server on port 7474 and my image runs on port 8000.

when I run my image I publish both ports (could I do this with EXPOSE?):

docker run -d --publish=7474:7474 --publish=8000:8000 linkurious

but only my server seems to run. if I hit http://[ip]:7474/ I get nothing. is there something special I have to do to make sure they both run?

* Edit I *

here's my Dockerfile:

FROM neo4j/neo4j:latest
RUN apt-get -y update
RUN apt-get install -y git
RUN apt-get install -y npm
RUN apt-get install -y nodejs-legacy
RUN git clone git://github.com/Linkurious/linkurious.js.git
RUN cd linkurious.js && npm install && npm run build
CMD cd linkurious.js && npm start

* Edit II *

to perhaps help explain my quandary, I've asked a different question

解决方案

EXPOSE is there to allow inter-containers communication (within the same docker daemon), with the docker run --link option.
Port mapping is there to map EXPOSEd ports to the host, to allow client-to-container communication. So you need --publish.

See also "Difference between "expose" and "publish" in docker".

See also an example with "Advanced Usecase with Docker: Connecting Containers"


Make sure though that the ip is the right one ($(docker-machine ip default)).


If you are using a VM (meaning, you are not using docker directly on a Linux host, but on a Linux VM with VirtualBox), make sure the mapped ports 7474 and 8000 are port forwarded from the host to the VM.

VBoxManage controlvm boot2docker-vm natpf1 "name,tcp,,7474,,7474"
VBoxManage controlvm boot2docker-vm natpf1 "name,tcp,,8000,,8000"


In the OP's case, this is using neo4j: see "Neo4j with Docker", based on the neo4j/neo4j/ image and its Dockerfile:

ENTRYPOINT ["/docker-entrypoint.sh"] 
CMD ["neo4j"]

It is not meant to be used for installing another service (like nodejs), where the CMD cd linkurious.js && npm start would completely override the neo4j base image CMD (meaning neo4j would never start).

It is meant to be run on its own:

# interactive with terminal
docker run -i -t --rm --name neo4j -v $HOME/neo4j-data:/data -p 8474:7474 neo4j/neo4j

# as daemon running in the background
docker run -d --name neo4j -v $HOME/neo4j-data:/data -p 8474:7474 neo4j/neo4j

And then used by another image, with a --link neo4j:neo4j directive.

这篇关于运行2个服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆