Run more Docker Compose project on the same port using nginx-proxy

See nginx-proxy

Go to Project 6 from the git repository root:

cd projects/p06

Create the proxy network:

docker network create public_proxy

Check the networks:

docker network ls

Navigate to the nginxproxy folder

cd nginxproxy

Start the proxy:

docker-compose up -d

Navigate to the web1 folder:

cd ../web1

At this point you need to have the XIP variable set as Welcome to Learn Docker’s documentation! refers to it.

Alternative option: set the XIP variable in the “.env” file:

Start the containers:

docker-compose up -d

Navigate to the web2 folder:

cd ../web2

Start the containers:

docker-compose up -d

Both of the services are available on port 80. Example:

http://web1.192.168.1.6.xip.io
http://web2.192.168.1.6.xip.io

This way you do not need to remove a container just because it is running on the same port you want to use for a new container.

Clean the project:

docker-compose down --volume
cd ../web1
docker-compose down --volume
cd ../nginxproxy
docker-compose down --volume