【发布时间】:2020-12-04 17:18:22
【问题描述】:
我在 Microsoft 的文档中引用了这篇文章:
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-apache?view=aspnetcore-3.1
有没有人尝试在 Docker 容器中完成这些步骤? 我已经有几天了,当我运行容器时,我无法让 kestrel-helloapp.service 文件自动启动我的应用程序。
运行容器后,我可以手动进入它并使用dotnet WebApplication3.dll 启动我的应用程序。
我的印象是这应该在启用服务文件后自动发生。
我能够让它工作的唯一方法是将它添加到 Dockerfile:
ENTRYPOINT ["dotnet" ,"WebApplication3.dll"]
但是当我这样做时,它会导致 Apache 服务器无法自动启动。
这是我的 Dockerfile:
FROM centos:7
# install sudo and dotnet sdk
RUN yum install sudo -y
RUN sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
RUN yum install epel-release -y
RUN yum install dnf -y
RUN sudo dnf install dotnet-sdk-3.1 -y
# copy app files over
COPY ["./publish/", "/var/www/helloapp/publish/"]
# install apache and enable it
RUN sudo yum -y install httpd mod_ssl
RUN systemctl enable httpd.service
RUN yum install initscripts -y
RUN sudo service httpd configtest
# copy and enable service file
COPY ["./kestrel-helloapp.service", "/etc/systemd/system/"]
RUN sudo systemctl enable kestrel-helloapp.service
# start apache
CMD ["-D", "FOREGROUND"]
ENTRYPOINT ["/usr/sbin/httpd"]
EXPOSE 80
docker 运行命令:
docker run -v "C:\Users\Nick\source\repos\docker-testing\version1\helloapp.conf:/etc/httpd/conf.d/helloapp.conf" -e "ASPNETCORE_URLS=http://+:8080" -p 80:80 -p 8080:8080 -t version1
helloapp.conf 文件:
<VirtualHost *:*>
RequestHeader set "X-Forwarded-Proto" expr="http"
</VirtualHost>
<VirtualHost *:8080>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ServerName www.example.com
ServerAlias *.example.com
ErrorLog /var/log/httpd/helloapp-error.log
CustomLog /var/log/httpd/helloapp-access.log common
</VirtualHost>
kesterl-helloapp.service 文件:
[Unit]
Description=Example .NET Web MVC App running on CentOS 7
[Service]
WorkingDirectory=/var/www/helloapp/publish
ExecStart=/usr/local/bin/dotnet /var/www/helloapp/publish/WebApplication3.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=apache
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
我知道配置是正确的,因为当我手动启动应用程序时一切正常。服务文件似乎没有在启动时启动应用程序。 任何帮助将不胜感激。谢谢!
【问题讨论】:
标签: c# linux apache docker .net-core