Artisan from host

Hello to every one!

I am newby into docker but until now could run “php artisan migrate” from host powershell and it worked, but I had to format, and right now is impossible run that command out of container.

Now when run “php artisan migrate” recive this message:

In Connection.php line 647:

could not find driver (SQL: select * from information_schema.tables where table_schema = webmotor_db and table_name = migrations)

As you guest my OS is Windows 10 Pro (build 17074 insider)
I use docker-compose.yml and it works fine

I would like fix that because my mind is going out with this stupid case.

Thanks a lot for your help

where is the database located? on the docker host?
what connection string you use in the php application in the container to connect back to the host?

note that the container has its OWN IP address… so inside the container, 127.0.0.1 mean INSIDE the container…

just like on the host 127.0.0.1 means this HOST.
(localhost is the same as 127.0.0.1, has the same behavior)

The database is in docker container as show the compose file:
version: '2’
services:

web:
build:
context: ./
dockerfile: web.dockerfile
volumes:
- ./:/var/www
ports:
- "8080:80"
links:
- app

La aplicación

app:
build:
context: ./
dockerfile: app.dockerfile

working_dir: /var/www
volumes:
  - ./:/var/www
links:
  - database
  - cache
environment:
  - "DB_PORT=3306"
  - "DB_HOST=database"
  - "REDIS_PORT=6379"
  - "REDIS_HOST=cache"

database:
image: mysql:5.7
environment:
- “MYSQL_ROOT_PASSWORD=secret”
- “MYSQL_DATABASE=webmotordb”
- “MYSQL_USER=pedro”
- "MYSQL_PASSWORD=secret"
ports:
- "33061:3306"
cache:
image: redis:3.0
ports:
- “63791:6379”

The PhpMyadmin

phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- database:mysql
ports:
- "8181:80"
environment:
PMA_USER: root
PMA_PASSWORD: secret
PMA_HOST: mysql

volumes:
dbdata:

I know that localhost is 127.0.0.1, I am newby but no so :wink:

The Laravel .env vars are the next:
DB_CONNECTION=mysql
DB_HOST=dbdata
DB_PORT=33061
DB_DATABASE=webmotor
DB_USERNAME=pedro
DB_PASSWORD=secret

I hope this could clarify your questions
Thanks

where is the name dbdata created for the db server? your connection string uses that name… but you don’t define it in the compose file

also where is the pma_host=mysql defined? the db server doesn’t have that name

I don`t understand, usually in the .env file define “DB_HOST = localhost” or 127.0.0.1 but I have been trying others ways.
dbdata is in volumes so:
volumes:
dbdata:

If you are so gentil could you explain how define every parameter, please

Thanks

for this discussion think of containers a machines on a network… completely separated from each other.

each machine mus have a name, that name is how you find the other machine on the network…

your connection string says ‘dbdata’, but that is NOT the name of the DB ‘machine’. it is a volume.
"DB_HOST=dbdata"
there was no NAME provided for the database ‘machine’ in the docker compose file.
or this
PMA_HOST: mysql

there was

database:
image: mysql:5.7

unless you specify otherwise, then NAME of the ‘machine’ matches the NAME of the docker compose ‘service’… in this case ‘database’

draw it out on a piece of paper or whiteboard…
three machines…

web
database
phpmyadmin

they each will have their own unique IP address…

so for phpmyadmin to connect to the mysql db on machine database the host name needs to be
PMA_HOST: database

looks like app container is now correct
DB_HOST=database

docker compose hides all the details…

after the containers are running ;look at their config with the docker inspect command

docker inspect container_id

1 Like

Thank you very much for your help. I have followed your instructions but I can not connect from host to mysql host

can u ping the mysql container from the host ?

did u enable the DB client username to connect to the mysql host from a remote system? by default this is not enabled

1 Like

the ping not answer nothing, loss all packets…
But I wonder how the “php artisan migrate” it was woriking before…without needless to enter into container…

what ip address did you use?

1 Like

I use the IP returned from “docker inspect container” that is 172.18.0.3

can u docker attach to the php container and then ping the database?

can u ping any of the containers from the host?

Not, I begin to think that I have not right communication between host and container, just sharing volumes

Maybe I should to create network… I don’t know