'Docker-compose Apache mapping external local directory to document root

I am pretty beginner with Docker, and I'm trying to create a local development LAMP (more exactly Apache, MariaDB, PHP) stack using docker-compose, existing Docker images from Docker hub and no Dockerfile if possible, to be used with several local web projects.

I'd like to map my local web project directory /Users/myusername/projects/myprojectname to the default document root for Apache container (which seems to be /app for the Apache image I'm using)

Here is my docker-compose.yml file:

version: "3"

services:
  mariadb:
    image: mariadb:10.5
    container_name: mariadb
    restart: always
    ports:
      - 8889:3306
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_USER=localmysqluser
      - MYSQL_PASSWORD=localmysqlpwd
  php:
    image: bitnami/php-fpm:7.4
    container_name: php
    ports:
      - 9000:9000
    volumes:
      - /Users/myusername/projects/myprojectname:/app
  apache:
    image: bitnami/apache:latest
    container_name: apache
    restart: always
    ports:
      - 8080:80
    volumes:
      - ./apache-vhosts/myapp.conf:/vhosts/myapp.conf:ro
      - /Users/myusername/projects/myprojectname:/app
    depends_on:
      - mariadb
      - php

But when I do docker-compose up -d then browse to http://localhost:8080/, I get zero data. Where am I wrong? Is my docker-compose.yml configuration wrong, or is it because of system rights?

I've been looking at this similar question, but I'd prefer not using any Dockerfile if possible.

Further question: is it possible to make a local directory /Users/myusername/projects/ browsable by Apache in my local browser?



Solution 1:[1]

As answered by J. Song, exposed port number of this Apache Docker image is 8080, not 80.

So we just need to change port mapping of Apache service to 8080:8080 instead of 8080:80.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bolino