OCSInventory-NG / OCSInventory-Docker-Stack

Docker stack for OCSInventory Server
GNU General Public License v3.0
42 stars 38 forks source link

MySQL Access denied #4

Closed fam4r closed 4 years ago

fam4r commented 5 years ago

General informations

Docker host's operating system :

uname -r
4.20.0-arch1-1-ARCH

Docker informations

Docker compose version :

docker-compose --version
docker-compose version 1.23.2, build 1110ad01

Docker version :

docker --version
Docker version 18.09.1-ce, build 4c52b901c6

Dockerfile:

version: '3'
services :
  web :
    image : ocsinventory/ocsinventory-docker-image:latest
    container_name : ocsinventory-server
    environment :
      OCS_DBNAME : retigest
      OCS_DBSERVER_READ : ocsinventory-db
      OCS_DBSERVER_WRITE : ocsinventory-db
      OCS_DBUSER : retigest
      OCS_DBPASS : testtest
    volumes :
      - ocsdownload:/usr/share/ocsinventory-reports/ocsreports/download/
      - ocssrv:/etc/ocsinventory-reports/
      - ocslib:/var/lib/ocsinventory-reports/
    links :
      - db
    ports :
      - 80:80
      - 443:443

  db :
    image : mysql:5.7
    container_name : ocsinventory-db
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD : testonly
      MYSQL_USER : retigest
      MYSQL_PASSWORD : testtest
      MYSQL_DATABASE : retigest
    volumes :
      - ./sql/:/docker-entrypoint-initdb.d/
      - ocsdata:/var/lib/mysql
    ports :
      - 3306:3306

volumes:
  ocsdata:
    driver: local
  ocssrv:
    driver: local
  ocslib:
    driver: local
  ocsdownload:
    driver: local

Problem's description

Hello,

I can't find a way to install OCS Inventory via Docker.

I used the provided docker-compose.yml file and changed the following variables (as you can see in the Dockerfile above):

OCS_DBNAME
OCS_DBUSER
OCS_DBPASS
MYSQL_ROOT_PASSWORD
MYSQL_USER
MYSQL_PASSWORD
MYSQL_DATABASE

1) I don't understand if the variables OCS_DBUSER/OCS_PASS and MYSQL_USER/MYSQL_PASSWORD must be the same. 2) Using the above Dockerfile, when I execute docker-compose up and go to http://localhost/ocsreports/ I get the following error:

ERROR: MySql connection problem 1045
Access denied for user 'retigest'@'172.23.0.3' (using password: YES)
ERROR: MySql connection problem 1045
Access denied for user 'retigest'@'172.23.0.3' (using password: YES)

So I connected to the ocsinventory-db container and I noticed two things:

docker exec -it ocsinventory-db mysql -u root -p
mysql> select user from mysql.user;
+---------------+
| user          |
+---------------+
| ocs           |
| root          |
| mysql.session |
| mysql.sys     |
| ocs           |
| root          |
+---------------+

Then, according to https://github.com/OCSInventory-NG/OCSInventory-Docker-Image/issues/12, i tried to put the install.php file into the directory /usr/share/ocsinventory-reports/ocsreports/ and went to http://localhost/ocsreports/install.php.

Using the default credentials root and mdp the page said:

Your database is OK.
No action taken.

Finally, clicking on Click here to enter OCS-NG GUI and submitting the credentials admin/admin I was able to login.

I can not understand: maybe the DB is not being updated with the provided environment variables? But why the retigest DB is being created?

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| ocsweb             |
| performance_schema |
| retigest           |
| sys                |
+--------------------+

It can be fixed or have I need to perform such operations manually like:

rolandsgs commented 5 years ago

Hi fam4r, i solved this issue just using MYSQL_PASSWORD and OCS_DBPASS with the same value. I think this occurs because OCS_DBPASS is used in z-ocsinventory-server.conf as the value for mysql connection in ocsinventory-server and the MYSQL_PASSWORD is used in ocsinventory-db.

Unfortunately the logs ocsinventory-db still emitting, despite i can work with ocs normally [Note] Access denied for user 'ocs'@'172.20.0.3' (using password: YES)

gillesdubois commented 4 years ago

Hi,

Our Docker image has been reworked completly. 2.6 / nightly / dev tags are now available.

A complete documentation is available on wiki. Compose files are now located on the image repository and not on this one anymore.

Regards, Gilles Dubois.