translate vagrant statements in docker statements

2019-09-19 09:03发布

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条回答
戒情不戒烟
2楼-- · 2019-09-19 09:30

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

查看更多
登录 后发表回答