在docker语句中翻译流浪汉语句 [英] translate vagrant statements in docker statements

查看:81
本文介绍了在docker语句中翻译流浪汉语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在docker命令中转换一个无业游民的文件,以设置测试服务器。我没有使用docker的经验,对于以下命令,我没有找到解决方案。

I have to translate a vagrant file in docker commands for setting up a test server. I have no experiance in using docker and for the following command I found no solution.

Vagrant.configure("2") do |config|

  config.vm.network(:forwarded_port, guest: 5432, host: 5432, host_ip: "127.0.0.1")

我尝试了类似
docker network create --gateway 127.0.0.1 forwarded_port

I tried something like docker network create --gateway 127.0.0.1 forwarded_port

的方法,但是我没有找到方法设置端口,但我不确定 forwarded_port是网络的名称还是后台方法的参数。

But I found no way to set the ports and I'm not sure if "forwarded_port" is the name for my network or an argument for a method in the background.

我很感谢您的帮助

Matthias

推荐答案

该特定行看起来会导致容器/ VM中的端口转发到主机,并且应该与选项 docker完全等效。运行-p 127.0.0.1:5432:5432 (其中这三个部分匹配 host_ip host ,以及来自Vagrant语句的来宾)。

That specific line looks like it causes a port from the container/VM to be forwarded out to the host, and it should be exactly equivalent to the option docker run -p 127.0.0.1:5432:5432 (where those three parts match host_ip, host, and guest from your Vagrant statement).

请注意,Docker环境和典型用法可能有所不同从典型的虚拟机设置。作为此处的一个具体示例,您通常不会尝试在应用程序容器内运行PostgreSQL数据库;您将单独启动一个数据库容器并将其告诉您的应用程序。典型的仅命令行设置可能是

Note that the Docker environment and typical usage can be different from typical VM setups. As a specific example here, you wouldn't generally try to run a PostgreSQL database inside your application's container; you'd separately launch a database container and tell your application about it. A typical command-line only setup might be

docker network create mynet
docker run -p 5432:5432 --net mynet --name db postgres:9.6
docker run -p 8080:8080 --net mynet --name app -e PGHOST=db myapp:20180914

Docker Compose是启动多个可协同工作的容器的常用工具(您可以找到许多应用程序和数据库 docker-compose的示例.yml 文件(通过阅读SO问题)。

Docker Compose is a frequently used tool for launching multiple containers that work together (and you can find many many examples of app+database docker-compose.yml files by reading through SO questions).

这篇关于在docker语句中翻译流浪汉语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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