capcom6 / android-sms-gateway

The SMS Gateway for Android™ app enables sending and receiving SMS messages through an API that can be accessed directly on the device or via a cloud server when direct device access is not possible.

Home Page:https://sms.capcom.me

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with MySQL Access in Docker Compose Deployment

sinanouri opened this issue · comments

I am encountering issues with MySQL access when deploying my application using Docker Compose with default configurations. Here are the details of the problem:

docker exec -it sms-gateway-db-1 bash

Access Denied for root User:
When trying to access MySQL as root, I receive the following error:

root@4eb357a57a38:/# mysql -u root -proot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Access Denied for sms User:
Similarly, attempting to access MySQL as the 'sms' user results in:

root@4eb357a57a38:/# mysql -u sms -psms
ERROR 1045 (28000): Access denied for user 'sms'@'localhost' (using password: YES)

Related Log Entry:
The Docker logs for docker logs sms-gateway-backend-1 show the following error related to MySQL access:

{
    "level": "error",
    "ts": 1718564791.296919,
    "caller": "fxevent/zap.go:59",
    "msg": "start failed",
    "error": "Error 1045 (28000): Access denied for user 'sms'@'172.24.0.3' (using password: YES)",
    "stacktrace": "go.uber.org/fx/fxevent.(*ZapLogger).logError\n\t/go/pkg/mod/go.uber.org/fx@v1.20.1/fxevent/zap.go:59\ngo.uber.org/fx/fxevent.(*ZapLogger).LogEvent\n\t/go/pkg/mod/go.uber.org/fx@v1.20.1/fxevent/zap.go:215\ngo.uber.org/fx.(*App).Start.func1\n\t/go/pkg/mod/go.uber.org/fx@v1.20.1/app.go:640\ngo.uber.org/fx.(*App).Start\n\t/go/pkg/mod/go.uber.org/fx@v1.20.1/app.go:645\ngo.uber.org/fx.(*App).run\n\t/go/pkg/mod/go.uber.org/fx@v1.20.1/app.go:587\ngo.uber.org/fx.(*App).Run\n\t/go/pkg/mod/go.uber.org/fx@v1.20.1/app.go:578\ngithub.com/capcom6/sms-gateway/internal/sms-gateway.Run\n\t/go/src/internal/sms-gateway/app.go:52\nmain.main\n\t/go/src/cmd/sms-gateway/main.go:28\nruntime.main\n\t/usr/local/go/src/runtime/proc.go:271"
}

Hello!

To better assist you, could you please provide your docker-compose.yml file?

For reference, you can find an example in the repository under the following paths:

This will help understand your configuration and troubleshoot the access issues you're experiencing.

I didn't change anything. I just cloned repository and renamed config.example.yml to config.yml and ran docker compose up -d inside deployments/docker-compose. All settings are default.

I've just tested the deployment using the same steps and didn't encounter any issues—it works fine for me. Could you please try to completely remove the stack by running docker-compose down -v and then recreate it with docker-compose up?

If the issue persists, you can verify the container's environment variables, which are used to configure MariaDB, by executing docker exec -it <container_id> env. Please check the values for MYSQL_USER, MYSQL_PASSWORD, and MYSQL_ROOT_PASSWORD; they should match the values specified in your docker-compose.yml file. Ensure that these have not been overridden elsewhere.

I could not find out what the problem was with the Docker Compose file from the Git repository, but I managed to make it work using the configuration below:

Folder structure:

sms_gateway
├── config.yaml
└── docker-compose.yaml

config.yml:

gateway: # gateway config
  mode: private # gateway mode (public - allow anonymous device registration, private - protected registration) [GATEWAY__MODE]
  private_token: my_private_token # access token for device registration in private mode [GATEWAY__PRIVATE_TOKEN]
http: # http server config
  listen: 127.0.0.1:3000 # listen address [HTTP__LISTEN]
database: # database
  dialect: mysql # database dialect (only mysql supported at the moment) [DATABASE__DIALECT]
  host: localhost # database host [DATABASE__HOST]
  port: 3306 # database port [DATABASE__PORT]
  user: sms # database user [DATABASE__USER]
  password: database_user_password # database password [DATABASE__PASSWORD]
  database: sms # database name [DATABASE__DATABASE]
  timezone: Europe/London # database timezone (important for message TTL calculation) [DATABASE__TIMEZONE]
fcm: # firebase cloud messaging config
  credentials_json: "{}" # firebase credentials json (for public mode only) [FCM__CREDENTIALS_JSON]
  timeout_seconds: 1 # push notification send timeout [FCM__DEBOUNCE_SECONDS]
  debounce_seconds: 5 # push notification debounce (>= 5s) [FCM__TIMEOUT_SECONDS]
tasks: # tasks config
  hashing: # hashing task (hashes processed messages for privacy purposes)
    interval_seconds: 15 # hashing interval in seconds [TASKS__HASHING__INTERVAL_SECONDS]

docker-compose.yaml:

version: '3.8'
services:
  backend:
    image: capcom6/sms-gateway
    environment:
      - CONFIG_PATH=config.yml
      - HTTP__LISTEN=0.0.0.0:3000
      - DATABASE__HOST=db
      - DATABASE__PORT=3306
      - DATABASE__USER=sms
      - DATABASE__PASSWORD=database_user_password
      - DATABASE__DATABASE=sms
    ports:
      - "127.0.0.1:3000:3000"
    volumes:
      - ./config.yml:/app/config.yml:ro
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
  db:
    image: mariadb:10.11
    environment:
      - MYSQL_ROOT_PASSWORD=database_root_password
      - MYSQL_DATABASE=sms
      - MYSQL_USER=sms
      - MYSQL_PASSWORD=database_user_password
    volumes:
      - mariadb-data:/var/lib/mysql
    restart: unless-stopped
    healthcheck:
      test:
        [
          "CMD",
          "mysqladmin",
          "ping",
          "-proot",
          "-h",
          "127.0.0.1"
        ]
      timeout: 5s
      retries: 10
volumes:
  mariadb-data:

and the i ran:

docker compose up -d

Very interesting because your setup looks the same in the MariaDB accounts configuration part.

If the problem is resolved, can I close the issue?

Yes it is resolved. Thanks