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
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 matchhost_ip
,host
, andguest
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 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).