简体   繁体   English

在本地服务器上暴露Docker容器

[英]Exposing docker container on local server

I have a nodejs-mongo db app that is running inside docker containers. 我有一个在docker容器中运行的nodejs-mongo数据库应用程序。 I can access it on localhost etc... 我可以在本地主机上访问它...

But now I would like to install/deploy these containers on a local server, so that I can access this application outside my network. 但是现在我想在本地服务器上安装/部署这些容器,以便可以在网络外部访问此应用程序。 Please note my server is Ubuntu 16.04.1 LTS (xenial) 请注意我的服务器是Ubuntu 16.04.1 LTS(xenial)

Also I would like to access Db from outside, so that I can send data to the Db using custom script. 另外,我想从外部访问Db,以便可以使用自定义脚本将数据发送到Db。

I am newbie in both networking and Docker. 我是网络和Docker的新手。 As a result I am struggling to understand what needs to be done. 结果,我努力去理解需要做什么。 Any pointers would be appreciated 任何指针将不胜感激

Here is the docker-compose.yml 这是docker-compose.yml

version: "2"
services:
    web:
        build: .
        volumes: # Use this to mount app from local disk
            - ./:/usr/src/app
        ports:
            - "8080:8080"
            - "5858:5858"
        entrypoint: node --debug=5858 app.js
        links:
            - mongo
    mongo:
        image: mongo
        ports:
            - "27017:27017"

Here is my Dockerfile 这是我的Dockerfile

FROM node:argon

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install

# Bundle app source
COPY . /usr/src/app

EXPOSE 8080
CMD [ "npm", "start" ]

Usual command that I give to start my containers docker-compose up --build -d 我给出的用于启动容器的常用命令docker-compose up --build -d

Here is docker ps result 这是docker ps结果

"node --debug=5858 ap"   13 minutes ago      Up 13 minutes       0.0.0.0:5858->5858/tcp, 0.0.0.0:8080->8080/tcp   nodemongochart_web_1

"/entrypoint.sh mongo"   13 minutes ago      Up 13 minutes       0.0.0.0:27017->27017/tcp                         nodemongochart_mongo_1

If by local server, you mean your own machine at home, you will need to do something called "Port Forwarding". 如果使用本地服务器,则意味着您在家中拥有自己的计算机,则需要执行称为“端口转发”的操作。 It's usually configurable in your router, and you'll be able to access your application via some kind of link like this : 它通常可以在路由器中进行配置,并且您将能够通过诸如以下这样的链接来访问您的应用程序:

http://you-personal-ip:8080

If you'll be using another host, not in your own network, they should provide you with an IP address, in that case, no need for port forwarding. 如果您要使用其他主机,而不是在您自己的网络中,则它们应为您提供IP地址,在这种情况下,无需端口转发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 很难将我的快递 docker 容器暴露给世界 - difficulties exposing my express docker container to the world 将Redis DB docker容器暴露给NodeJS docker容器 - Exposing Redis DB docker container to a NodeJS docker container 如何从 AWS SAM 本地 Docker 容器访问另一个 Docker 容器(运行节点快速服务器)? - How do I access another Docker container (running a node express server) from a AWS SAM Local Docker container? 暴露在Docker上运行的节点服务器不起作用 - Exposing node Server running on docker doesn't work 无法访问docker容器中的服务器 - Cannot access server in docker container 如何在本地访问Docker容器应用程序? - How to access Docker container app on local? 从 docker 容器连接到本地 mongodb - connecting to local mongodb from docker container docker 容器中的服务器无法连接到另一个 docker 容器中的 postgres 数据库 - Server in docker container unable to connect to postgres database in another docker container 无法使用 docker 上下文使用 docker 将本地目录复制到远程容器 - Can not copy local directory to remote container with docker using docker context 在Kubernetes中精心安排的Docker容器中的缓存服务器 - Caching server in Docker container orchestrated in Kubernetes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM