Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

monstajamss's avatar

Database reset in Docker after power down

I am trying to run laravel on docker but i use the command docker-compose down my laravel database reset when i bring it back up using docker-compose up -d.

And when i try to run php artisan migratei get this error

SQLSTATE[HY000] [2002] php_network_getaddresses: gethostbyname failed. errno=0 (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations and table_type = 'BASE TABLE')

How can i avoid this?

0 likes
3 replies
monstajamss's avatar

@tippin i figured i had this in my docker.yml

  mysql:
    image: mysql:5.7.22
    container_name: mysql
    restart: unless-stopped
    tty: true
    ports: 
      - "4306:3306"
    volumes:
      - ./mysql:/ar/lib/mysql
    environment:
      MYSQL_DATABASE: homestead
      MYSQL_USER: homestead
      MYSQL_PASSWORD: secret
      MYSQL_ROOT_PASSWORD: secret
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    networks: 
      - laravel

instead of

  mysql:
    image: mysql:5.7.22
    container_name: mysql
    restart: unless-stopped
    tty: true
    ports: 
      - "4306:3306"
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      MYSQL_DATABASE: homestead
      MYSQL_USER: homestead
      MYSQL_PASSWORD: secret
      MYSQL_ROOT_PASSWORD: secret
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    networks: 
      - laravel

But how can i run php artisan migrate in my laravel folder instead of docker-compose exec php php /var/www/html/artisan migrate

Tippin's avatar

@monstajamss Not entirely sure why you have the php - folders - artisan php /var/www/html/artisan migrate. But in your docker compose you should designate your main laravel app as a service, then just docker-compose exec app php artisan:migrate . If you really do not like typing all of that, you can always make an alias in your terminal.

Digital ocean has a decent tutorial as well:

https://www.digitalocean.com/community/tutorials/how-to-containerize-a-laravel-application-for-development-with-docker-compose-on-ubuntu-18-04

Please or to participate in this conversation.