maurobonfietti / slim4-api-skeleton

Useful skeleton for RESTful API development with PHP and Slim 4.
http://bit.ly/2nNNOZi
MIT License
132 stars 32 forks source link

About running the docker compose #48

Closed ghost closed 3 years ago

ghost commented 3 years ago

I'm a beginner in docker beginner and try to using docker compose start up the project and check the db

but when I add a view for check db in the docker-compose file,

but it will display error message when I login

What problem in the docker compose file?

Ps.

  1. localhost:8080/
  2. 127.0.0.1:8080/ 1 and 2 not work go to page then login still show the error

Thanks.

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name does not resolve

2 1 3
maurobonfietti commented 3 years ago

Hi @mazecat !

In you adminer login, try to use the hostname "mysql" instead of "db". Also, adminer need to use a mysql user password.

So, stop all your containers. Edit your docker-compose.yaml and .env files. Start docker containers with composer up or docker-compose up -d --build.


Screen Shot 2021-01-02 at 14 05 39
Screen Shot 2021-01-02 at 14 05 53
Screen Shot 2021-01-02 at 14 06 04

This is for example my docker-compose.yaml file:

version: '3'

services:
  nginx:
    image: nginx:latest
    container_name: slim4-api-skeleton-nginx-container
    ports:
      - "8081:80"
    volumes:
      - ./:/var/www/html
      - ./docker/nginx/conf.d:/etc/nginx/conf.d

  php-fpm:
    build: ./docker/php7
    container_name: slim4-api-skeleton-php-container
    links:
      - mysql
    environment:
      - PHP_FPM_ENABLE=1
      - PHP_FPM_SERVER_ADDR=php
      - PHP_FPM_SERVER_PORT=9000
      - PHP_FPM_TIMEOUT=${HTTPD_TIMEOUT_TO_PHP_FPM:-180}
    volumes:
     - ./:/var/www/html

  mysql:
    image: mysql:5.7
    ports:
      - 33060:3306
    environment:
      MYSQL_DATABASE: slim4_api_skeleton
      MYSQL_ROOT_PASSWORD: example

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

volumes:
  my-data:

and this is my .env file:

DB_HOST='mysql'
DB_NAME='slim4_api_skeleton'
DB_USER='root'
DB_PASS='example'
DB_PORT='3306'

DISPLAY_ERROR_DETAILS=true
SLIM_BASE_PATH=''

I hope it'll work for you. GoodBye.-

ghost commented 3 years ago

@maurobonfietti Thanks. it's work for me.