Hi guys, Im new in Docker. I tried set up my laravel application using a Docker. What im not understand is the "ports:" part in docker-compose.yml. So i tried to setup my MongoDB like this :
But, if i set my laravel mongodb .env files port to 27018, It wont connect. But if i set it to 27017, it connects. What is wrong here? Do i miss understand the port meaning?
I dont know what port mongodb runs on but I can explain how docker works.
ports:
- 27017:27018
Here you are exposing port 27017 to your local system. That means that you can connect to the database from your OS using localhost:27017. The port after the colon is the local port (27018) on the container
So it just links 27017 external with 27018 internal
It does not change anything inside docker, so you still need to use the default (27018 I assume) port when using laravel
The great thing about this is that you can expose the database to you local system without getting port conflicts