I’m trying to run "php artisan migrate" in docker app container bash, after successfully installing mysql, nginx, php and etc. containers.
But this error comes up :
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = code_clan and table_name = migrations and table_type = ‘B
ASE TABLE’)
This is my folder/files structure :
> docker-my-app(folder)
> docker(folder)
> nginx(folder)
> default.conf
> php-fpm(folder)
> Dockerfile
> src(folder)
> www(folder)
> Laravel Project Files...
> **.env**
**docker-compose.yml**
This is my composer file (docker-compose.yml):
version: '3.8'
services:
nginx:
ports:
- "80:80"
image: nginx
tty : true
restart: unless-stopped
volumes:
- ./src/www:/usr/share/nginx/html:delegated
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
networks:
- thenetwork
app:
build: ./docker/php-fpm
container_name: myapp
tty : true
restart: unless-stopped
environment:
SERVICE_NAME: myapp
SERVICE_TAGS: dev
networks:
- thenetwork
working_dir: /usr/share/nginx/html
volumes:
- ./src/www:/usr/share/nginx/html
- ./data/upload:/storage/uploads
memcached:
image: memcached
mysql:
ports:
- "3306:3306"
image: mysql:5.6
restart: unless-stopped
tty: true
volumes:
- mysqlvolume:/var/lib/mysql
- ./data/mysql-import:/docker-entrypoint-initdb.d
environment:
- MYSQL_ROOT_PASSWORD=pwd
- MYSQL_HOST=localhost
- MYSQL_PORT=3306
networks:
- thenetwork
redis:
ports:
- "6379:6379"
image: redis
#Docker netwtorks
networks:
thenetwork:
driver: bridge
volumes:
mysqlvolume:
driver: local
This is my .env file (inside the root of laravel project):
APP_NAME=MyApp
APP_ENV=local
APP_KEY=base64:generatedKey
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=daily
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lara_app
DB_USERNAME=root
DB_PASSWORD=pwd
...
Inside docker-my-app cmd, I run :
docker exec -it myapp bash
And inside there, I run :
/usr/share/nginx/html$ php artisan migrate
all the containers, including mysql are running successfuly.
And the error mentioned at the beginning happens.
Can you figure out what happens here?
2
Answers
After trying different ways:
.env file :
I am on MAMP. I just changed the port to 8889 and the password. It works
php artisan config:cache
php artisan cache:clear
php artisan migrate