Search code examples
phpdockernginxdocker-composedockerfile

How to have multiple projects running at the same time on docker


I am new to docker and having trouble working with multiple projects since they all run on the same port.

My docker-compose.yml:

enter image description here

My ../backend-web/Dockerfile:

FROM nginx

COPY nginx.conf /etc/nginx/conf.d/default.conf

My nginx.conf: enter image description here

And my .env file from where the ports are loaded:

DB_HOST=database-service
DB_ROOT_PASSWORD=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=

BACKEND_PORT=443
DB_PORT=3306
REDIS_PORT=6379
PHP_FPM_INSTALL_XDEBUG=true

Now this all works when I do docker-compose up, I can access https://localhost, but I want to have more than 1 projects, when i try to use same docker compose file for other projects it does not work because it uses the same port. I tried changing the 443 to 444 and mysql port to 3307 but then it does not load https://localhost:444.

How can I solve this issue?


Solution

  • I briefly worked with docker, but remember in some instances you have to rebuild container. Try docker-compose up --build after changing the port?