问题描述
我创建了laravel应用,然后创建了Dockerfile
:
FROM PHP:7.4-cli
RUN apt-get update -y && apt-get install -y libmcrypt-dev
RUN curl -sS https://getcomposer.org/installer | PHP -- --install-dir=/usr/local/bin --filename=composer
RUN docker-PHP-ext-install pdo
#mbstring
workdir /app
copY . /app
RUN composer install
EXPOSE 8000
CMD PHP artisan serve --host=0.0.0.0 --port=8000
然后我运行了sudo docker build -t myApp .
和 sudo docker run -it -p 8000:8000 news-organizer
。一切正常。
当我将此文件夹(带有Dockerfile)复制到另一个位置并运行composer update --ignore-platform-reqs
,sudo docker build --no-cache -t theApp .
和sudo docker run -it -p 8888:8888 theApp
时,Web App将启动。输入127.0.0.1:8888
时出现 500错误。
我已经将所有权限设置为sudo chmod 755 -R <myLaravelFolder>
。我还尝试设置其他端口号。新文件夹的Dockerfile
是:
FROM PHP:7.4-cli
RUN apt-get update -y && apt-get install -y libmcrypt-dev
RUN curl -sS https://getcomposer.org/installer | PHP -- --install-dir=/usr/local/bin --filename=composer
RUN docker-PHP-ext-install pdo
#mbstring
workdir /app
copY . /app
RUN composer install
EXPOSE 8888
CMD PHP artisan serve --host=0.0.0.0 --port=8888
我的基本想法是:创建Laravel网络应用。然后创建一个Dockerfile并将其上传到某个地方。然后其他人可以下载Web App,安装Docker并运行sudo docker build -t <myImage> .
和sudo docker run -it -p 8000:8000 <myImage>
。这样,他们就可以在计算机上将我的Laravel应用程序用作docker容器。
我将xubuntu 20.04作为操作系统运行。
解决方法
感谢您对日志的提示。最终,我发现我必须生成应用程序密钥。可以通过[Table("Collections")]
public class CollectionModel
{
[Key]
public int Id { get; set; }
public string name {get; set; }
[ForeignKey("FK_Item_CollectionId")]
public List<ItemModel> Items { get; set; }
}
[Table("Items")]
public class ItemModel
{
[Key]
public int Id { get; set; }
public int FK_Item_CollectionId { get; set; }
}
完成。