Home>

As the title suggests, I don't understand the meaning of the following settings in the vagrantfile.
What are you doing? I would appreciate it if you could teach me systematically.

config.vm.network "forwarded_port", guest: 3000, host: 3000
  • Answer # 1

    Vagrant is a command to manage virtual servers.
    The virtual server starts another OS on the OS as hardware.
    At this time, the OS on the hardware is called the host OS, and the OS on the virtual server is called the guest OS.

    A virtual network interface is created in the guest OS just like a host OS has a network interface, and a network bridge (such as a virtual router) connects the host-side network interface and the guest-side network interface. )will be created.

    Normally, the IP on the guest side is virtually attached, so it cannot be accessed from an external network other than the host PC.

    The following is the question,

    config.vm.network "forwarded_port", guest: 3000, host: 3000


    It is a setting to access the port number 3000 of the guest side IP when it is accessed by the host side IP with the port number 3000.

    When setting the above settings and setting up a web server (http) on the guest side with port number 3000
    On the host PC, you can access the guest WEB server when you access http: // localhost: 3000.

    You can also access the guest WEB server from an external PC using the IP address of the host PC from an external PC with http: // host PC IP address: 3000.

    If a web server with the same port (for example, 3000) has already been set up on the host side

    config.vm.network "forwarded_port", guest: 3000, host: 3010


    By changing the port number on the host side like this
    On the host PC, you can access the WEB server (port 3000) on the guest side when you access http: // localhost: 3010.