简体   繁体   English

php 容器使用 docker-compose 不断重启

[英]php container keeps restarting using docker-compose

I have the following docker-compose file.我有以下 docker-compose 文件。 When I try to up the file the mysql container start, but the php one keeps on restarting.当我尝试升级文件时,mysql 容器启动,但 php 容器不断重启。 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

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.您收到Interactive shell消息的原因是因为这是php:alpine3.12图像的 output 的 Z78E6221F6393D14CE6DZ,因此它会不断记录该消息。

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?我真的不知道 PHP 但看起来图像尝试执行的命令是docker-php-entrypoint php -a ,这会启动交互式 Z2591C98B70119FE624898B1E424B5,对吗?

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:为此,在docker-compose.yml文件中,只需添加最后两行:

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.然后您的容器将继续运行,您将能够与它进行交互。

The reason is that you are using an inappropriate PHP image.原因是您使用了不合适的 PHP 映像。 If you want to run PHP with a web server then you should use one of:如果您想使用 web 服务器运行 PHP,那么您应该使用以下之一:

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

See Image Variants in the Docker documentation.请参阅 Docker 文档中的图像变体

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM