Wordpress: 403 forbidden error

I’m trying to use a Docker image under WSL2 (Ubuntu 22.04), but I keep getting a 403 forbidden error.

The image is working fine on my desktop machine (I can visit localhost:8000 and it shows my project, I can use ssh and git etc.).

However, on my laptop I can’t get this to work with the same setup. So it must be machine specific.

Here is my docker image:

services:
# WordPress
wordpress:
    image: wordpress:latest
    ports:
        - "8000:80"
    environment:
        WORDPRESS_DB_HOST: db
        WORDPRESS_DB_USER: wordpress
        WORDPRESS_DB_PASSWORD: wordpress_password
        WORDPRESS_DB_NAME: wordpress

    volumes:
        - ./wp-content:/var/www/html/wp-content
        - ./wp-cli.yml:/var/www/html/wp-cli.yml
    depends_on:
        - db
    # Install WP-CLI
    command: >
        bash -c '
        curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
        && chmod +x wp-cli.phar
        && mv wp-cli.phar /usr/local/bin/wp
        && apache2-foreground
        '

# MySQL Database
db:
    image: mysql:5.7
    environment:
        MYSQL_DATABASE: wordpress
        MYSQL_USER: wordpress
        MYSQL_PASSWORD: wordpress_password
        MYSQL_RANDOM_ROOT_PASSWORD: "1"
    volumes:
        - db_data:/var/lib/mysql

# phpMyAdmin
phpmyadmin:
    image: phpmyadmin/phpmyadmin
    ports:
        - "8080:80"
    environment:
        PMA_HOST: db
    depends_on:
        - db

volumes:
    db_data:

I have my project-folder with the image docker-compose.yml shown above, I can do docker compose up -d and the image is booting up.

But when I visit localhost:8000 I’m getting 403 forbidden.

What can I do to fix this?

Any help is highly appreciated. Thanks.

I’ve tried to shutdown apache2 via sudo systemctl stop apache2 but still I’m not able to see my project (keep getting 403 forbidden).

I’ve been searching for hours without any result.

Hello dear,

did you fix that issue?
I have same issue and i have tried a lot way but it was same, if you fix it please share with us

Please create your own topic, and add all details required by someone else about how you configured everything, and how the exact error message looks like.

We can help with the mechanics of docker. In this topic, the problem is not with the docker mechanics, but is thrown by the application inside the container itself, which denies access to the application.