1

I've been trying to figure out how to connect to a mariadb container while using podman-compose and I keep getting an error.

Here's what I've done:

Software Versions

podman version = 3.3.1
podman-compose version = podman-compose-0.1.7-2.git20201120.el8.noarch`

docker-compose.yml

version: '3'
services:
  db:
    image: mariadb:latest
    environment:
      MARIADB_USER: user
      MARIADB_PASSWORD: pass
      MARIADB_DATABASE: testdb
      MARIADB_ROOT_PASSWORD: rootpass
    volumes:
      - db_data:/var/lib/mysql

When I spin this container up using: podman-compose up -d

Then try to connect to this database using:

podman exec -it project_db_1 mariadb -uroot -prootpass

I get this error:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

I get this error both as a regular user and as the root user.

Yet, when I run the same container with podman:

Podman Command

podman run -d \
--name mariadb \
-e MARIADB_USER=user \
-e MARIADB_PASSWORD=pass \
-e MARIADB_DATABASE=testdb \
-e MARIADB_ROOT_PASSWORD=rootpass \
mariadb:latest

Then try to connect to this database using:

podman exec -it mariadb mariadb -uroot -prootpass

I am able to successfully login.

Can anyone please explain to me what I'm doing wrong with podman-compose or why it's not allowing me to login with the credentials I've given?

2 Answers 2

0

OK, for anyone that want's to know what I did to fix this... Firstly, I uninstalled podman & podman-compose because there were just too many issues with it, so I installed docker & docker-compose.

Secondly, when I ran this script in docker-compose, I got an error that wasn't showing up in podman-compose.

Error: services.db.environment must be a mapping

After Googling that error, I found out that I needed to format the environment section like this:

version: '3'
services:
  db:
    image: mariadb:latest
    environment:
      - MARIADB_USER=user
      - MARIADB_PASSWORD=pass
      - MARIADB_DATABASE=testdb
      - MARIADB_ROOT_PASSWORD=rootpass
    volumes:
      - db_data:/var/lib/mysql

After I fixed that, docker-compose ran beautifully and I could connect to my database, even from another container. I did do a test using podman-compose with this code fix, and it still wouldn't work. So I'm just going to use docker until podman fixes their issues.

Sign up to request clarification or add additional context in comments.

1 Comment

Both ways are valid object and array syntax. At least with docker. I assume that's with podman the case too. So I am guessing your issue was something else.
0

You need to make sure to bind to the "public" address of the container. It will by default bind to 0.0.0.0. On that interface you cannot access it from other pods.
Add a command to the service, and set --bind-address. Like this:

services:
  db:
    image: docker.io/mariadb:latest
    command: --bind-address=db

This will make it listen to the correct interface :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.