Unable to connect to localhost (docker-compose on docker desktop)

First time using docker. I used docker-compose to pull latest official wordpress image.

Created .yml file:

version: “3.9”

services:
db:
image: mysql:5.7
platform: linux/x86_64
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress

wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- wordpress_data:/var/www/html
ports:
- “8000:80”
restart: always
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
wordpress_data: {}

Run: docker-compose up

Everything worked fine when connecting to port 8000 on localhost…

Then I did the same, with the following alterations:

services:
db:
image: mysql:5.7
platform: linux/x86_64
volumes:
- db_data_1:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress

wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- wordpress_data_1:/var/www/html
ports:
- “8080:8080
restart: always
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data_1: {}
wordpress_data_1: {}

Note: I changed the data volume name and mapped ports 8080:8080 but everything else was left the same and I can’t connect to the wordpress login page. What am I doing wrong here?

Hi :slight_smile:

ports:
- “8080:8080"

This is your issue, the first port is what you connect to from the outside, and the second, is the service running in the container, normally you dont change the last port, because, it dosnt change (in this case)

so what you want is " - 8080:80", meaning port 8080 from outside the container, should connect to port 80 in the container