Pixelairport's avatar

Ports with lando and two projects

I use lando with docker to create my projects local. When I start a project everything works. But I want to test something, where I need to start two lando servers inside my docker. Problem is that the first will start, but second has an error. I think it is because of the ports. But I just dont understand how to solve this. I changed the ports but nothing works. I have in both files this:

// Lando file

// ...
services:
  node:
    type: node:18
    scanner: false
    ports:
      - 3009:3009
    build:
      - npm install
// ...
// vite file

//...
server: {
        // ...
        host: true,
        port: 3009,
        // ...
    },
//...

For example tried 3039:3009 in lando file. But then i need to tell my computer to use 3039 also for node... not sure how to do this or if im wrong.

0 likes
2 replies
LaryAI's avatar
Level 58

It seems like you're encountering a port conflict because both of your Lando projects are trying to use the same port (3009). To resolve this, you need to assign different ports to each project. Here's how you can do it:

For your first project, you can keep the configuration as is:

// Lando file for Project 1

// ...
services:
  node:
    type: node:18
    scanner: false
    ports:
      - 3009:3009
    build:
      - npm install
// ...

And for your Vite configuration in the first project:

// vite file for Project 1

//...
server: {
  // ...
  host: true,
  port: 3009,
  // ...
},
//...

For your second project, you need to change the ports in both the Lando configuration and the Vite configuration to a different port, for example, 3010:

// Lando file for Project 2

// ...
services:
  node:
    type: node:18
    scanner: false
    ports:
      - 3010:3010
    build:
      - npm install
// ...

And for your Vite configuration in the second project:

// vite file for Project 2

//...
server: {
  // ...
  host: true,
  port: 3010,
  // ...
},
//...

By doing this, you ensure that each project listens on a different port, avoiding any conflicts. Remember to use these new port numbers when you're trying to access your projects in the browser.

After making these changes, you should be able to start both Lando servers without any port conflict errors. Make sure to restart Lando for the changes to take effect:

lando stop && lando start

Do this for both projects after you've updated their respective configurations.

Pixelairport's avatar

Ok. Not sure why but with 3010 it works. Is there a number from/till i can use the ports? For example everything from 3009-3020 can be used here?

Please or to participate in this conversation.