Conflicting port 80 on nginx and apache Docker containers

Viewed 549

Is there any way to stop 2 conflicting docker containers on the same machine since they are both using the internal?! or container port 80? I have one ngnix docker that runs on port 9000 from the browser.

916aa1f58ca3        nginx:1.21.6-alpine                      "/docker-entrypoint.…"   3 minutes ago       Up 3 minutes             0.0.0.0:9000->80/tcp  

and a second Apache2 that is mapped to external port 88.

4a3ba2c4847b        apache-master_php                       "docker-php-entrypoi…"   3 hours ago         Up 3 seconds             80/tcp, 0.0.0.0:88->88

They both run together except when I send a request to the apache machine. Accessing the apaches index.html on port 88 on the browser crashes the machine.

Is there a way around this?

docker-compose.yml looks like this:

apache: 
       ports:
          - 88:88
        volumes:
          - ./src:/var/www/html/

for ngnix:

 nginx:
    ports:
      - "$SENTRY_BIND:80/tcp"
    image: "nginx:1.21.6-alpine"
1 Answers

Conflict can never occur between containers, as docker will assign above containers to a private network created specifically for these services and each container will have its own private ip.

docker configuration should be as below, assuming apache is running using the default configurations

apache: 
       ports:
          - 80:88
        volumes:
          - ./src:/var/www/html/

your configurations is telling docker to map container port 88 to host port 88 which is wrong.

I think you should read the docs https://docs.docker.com/network/

Related