translate vagrant statements in docker statements

。_饼干妹妹 提交于 2020-01-07 08:37:25

问题


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")

I tried something like docker network create --gateway 127.0.0.1 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.

I am grateful for any help

Matthias


回答1:


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).

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 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).



来源:https://stackoverflow.com/questions/52329040/translate-vagrant-statements-in-docker-statements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!