skip to Main Content

I have the following docker-compose file. When I try to up the file the mysql container start, but the php one keeps on restarting. When I look at the logs all I get is "interactive shell" constantly. Any idea why this is happening?

---
version: "3"
services:
  web:
    image: php:alpine3.12
    restart: unless-stopped
    volumes:
      - web_Data:/var/www/html
    ports:
      - 80:80
      - 443:443
    
  mariadb:
    image: mariadb
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: Password1
    volumes:
      - mariadb_Data:/var/lib/mysql
    ports:
      - 3306:3306
volumes:
  web_Data:
  mariadb_Data:
    driver: local

2

Answers


  1. The reason you are getting Interactive shell message it’s because that’s an output of php:alpine3.12 image and since your container is constantly restarting, it keeps logging that message.

    I don’t really know PHP but it looks like the command that the image tries to do is docker-php-entrypoint php -a, and that starts an interactive shell, am I right?

    If that is the case, then you need to run it in interactive mode. To do that, in docker-compose.yml file, just add the last 2 lines:

    web:
        image: php:alpine3.12
        restart: unless-stopped
        volumes:
          - web_Data:/var/www/html
        ports:
          - 80:80
          - 443:443
        stdin_open: true
        tty: true       
    

    Then your container will keep running and you will be able to interact with it.

    Login or Signup to reply.
  2. The reason is that you are using an inappropriate PHP image. If you want to run PHP with a web server then you should use one of:

    • php:<version>-fpm
    • php:<version>-apache

    See Image Variants in the Docker documentation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search