services:
db:
image: mariadb
ports:
- 3306:3306
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
restart: always
volumes:
- db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=pw
- MYSQL_PASSWORD=pw
- MYSQL_DATABASE=db
- MYSQL_USER=user
I used this to create a database, ran docker-compose up, then tried to access the database with:
sudo mysql -u user -h 127.0.0.1:3306 -p
But I get the following error:
ERROR 2005 (HY000): Unknown MySQL server host '127.0.0.1:3306' (-2)
It seems like the port 3306 isn't actually exposed and I don't understand why.