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
The reason you are getting
Interactive shell
message it’s because that’s an output ofphp: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:Then your container will keep running and you will be able to interact with it.
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.