docker工人:显示链接容器的开放端口
如果我检查官方的mongo泊坞窗图像,我可以看到它暴露了端口27017
$ docker inspect mongo ... "ExposedPorts": { "27017/tcp": {} }, ...
我已经运行图像,绑定内部端口在我的主机上相同:
$ docker run -p 27017:27017 -d --name db mongo
我现在在交互模式下运行我自己的图像,启动bash
$ docker run -i -t --link db:db_1 cd9b5953b633 /bin/bash
在我的dockerized容器中,如果我试图显示开放的端口,没有什么是倾听的。
$ netstat -a Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node Path
我在这里做错了什么? 我怎样才能从我的dockerized容器连接到Mongo容器?
如果它有一些用处,这里是我的Dockerfile:
# https://registry.hub.docker.com/u/dockerfile/nodejs/ (builds on ubuntu:14.04) FROM dockerfile/nodejs MAINTAINER My Name, me@email.com ENV HOME /home/web WORKDIR /home/web/site RUN useradd web -d /home/web -s /bin/bash -m RUN npm install -g grunt-cli RUN npm install -g bower RUN chown -R web:web /home/web USER web RUN git clone https://github.com/repo/site /home/web/site RUN npm install RUN bower install --config.interactive=false --allow-root ENV NODE_ENV development # Port 9000 for server # Port 35729 for livereload EXPOSE 9000 35729 CMD ["grunt"]
Docker创build一个Network命名空间,所以在你的容器中,你将看不到主机的暴露端口。
在你的用例中,如果你只需要从其他容器访问它,你不需要用-p
运行mongo。 --link
将简单地“注入”链接的容器信息作为environementvariables。
从你的新容器中,你可以做env
来查看列表,并且你将得到类似于DB_1_PORT_27027_TCP_ADDR
和你可以连接的mongo容器的私有IP。
- 如果机器处于不同的虚拟networking/子网中,在Docker Swarm上运行的Flink无法parsingjobmanager
- Jenkins:在构build映像时将(环境)variables传递给Docker
- 在Docker中如何附加到被恶魔化的容器
- stream浪者箱子和docker提供者:巨人和Kafka
- 从bash脚本运行“mysql”命令
- 带有Intellij的Ruby远程SDKconfiguration中断 – workarround?
- 群集模式:检查pipe理节点上的工作节点的容器
- Docker在Windows Server 2012r2上
- 链接的docker-compose制作http请求的容器