gpt4 book ai didi

docker - 无法读取已安装的卷

转载 作者:行者123 更新时间:2023-12-02 20:03:54 25 4
gpt4 key购买 nike

我正在为一个由 React-TypeScript 前端、ASP.NET Core 2 后端、SQL Server db 组成的应用程序对接我们的开发环境。

我相信我已经接近完成这项工作,但我遇到了一个问题,即 .NET 核心容器无法读取或写入已安装的卷。

我的文件夹结构如下:

proj
docker-compose.yml
.env
-> src
-> db
-> obj
-> build
-> .sql files
-> Dockerfile
-> server
-> .NET Core solution with many projects
-> Dockerfile
-> ui-client
-> react app
-> Dockerfile

服务器/Dockerfile:
FROM centos:7

# .NET Core
# Register repository
RUN rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm

# Install .NET Core and dependencies
RUN yum install -y dotnet-sdk-2.1

# Update and clean
RUN yum -y update
RUN yum clean all

# Configure Kestrel
ENV ASPNETCORE_URLS http://+:5001
ENV DOTNET_RUNNING_IN_CONTAINER true
ENV DOTNET_USE_POLLING_FILE_WATCHER true
ENV NUGET_XMLDOC_MODE skip

# Reference the environment
VOLUME [ "/app", "/.keys", "/logs"]

最小的 .env 示例:
PROJ_KEYS=~/.keys/proj
PROJ_CERT=/.keys/cert.pem
PROJ_KEY=/.keys/proj.pfx
PROJ_KEY_PW=ThisIsAFakePassword
PROJ_LOGGING_DIR=~/work/logs
SERILOG_DIR=/logs

docker -compose.yml:
version: "3"
services:

coreapi:
build: ./src/server
ports:
- "5001:5001"
depends_on:
- mssql
volumes:
- ./src/server:/app
- ${PROJ_KEYS}:/.keys
- ${PROJ_LOGGING_DIR}:/logs
environment:
PROJ_CERT: ${PROJ_CERT}
PROJ_KEY: ${PROJ_KEY}
PROJ_KEY_PW: ${PROJ_KEY_PW}
PROJ_LOG_DIR: ${SERILOG_DIR}
working_dir: "/app/API"
command: ["dotnet", "run"]
networks:
local:
aliases:
- coreapi

当我 docker-compose up它能够构建所有必需的图像,但是当 coreapi 容器启动时出现此错误:
coreapi_1  | Using launch settings from /app/API/Properties/launchSettings.json...
coreapi_1 | [18:58:22 INF] Starting Proj's API
coreapi_1 | [18:58:22 FTL] API terminated unexpectedly
coreapi_1 | System.IO.DirectoryNotFoundException: Could not find a part of the path '/Users/<my_user>/.keys/proj/cert.pem'.
coreapi_1 | at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
coreapi_1 | at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
coreapi_1 | at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
coreapi_1 | at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
coreapi_1 | at System.IO.File.ReadAllBytes(String path)
coreapi_1 | at API.Options.ConfigExtensions.ConfigureProjOptions(IServiceCollection services, IConfiguration configuration, IHostingEnvironment environment) in /app/API/Options/ConfigExtensions.Options.cs:line 54
coreapi_1 | at API.Startup.ConfigureServices(IServiceCollection services) in /app/API/Startup.cs:line 32
coreapi_1 | --- End of stack trace from previous location where exception was thrown ---
coreapi_1 | at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
coreapi_1 | at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
coreapi_1 | at Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
coreapi_1 | at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
coreapi_1 | at API.Program.Main(String[] args) in /app/API/Program.cs:line 33
proj_coreapi_1 exited with code 1

我已经检查了我在 docker 容器上挂载的目录的权限。
ls -la ~/.keys/proj给出:
-rw-r--r--  1 my_user  staff   977 Jun 21 08:59 cert.pem
-rw-r--r-- 1 my_user staff 1704 Jun 21 08:59 key.pem
-rw-r--r-- 1 my_user staff 2285 Jun 21 09:00 proj.pfx

我的猜测是,我在 docker-compose 文件或 .env 文件中输入了错误的内容,但我很困惑,如果我在文件的正确位置得到错误点,那怎么可能我正在努力阅读。

另外值得注意的是,即使它在容器外失败时确实写入了日志文件,但在失败时不会写入日志文件。让我觉得日志记录量也没有正确配置。

如何将文件夹作为卷安装在我的容器上,以便应用程序可以使用该文件夹中的 key ?

最佳答案

解决了。

我不得不改变我的.env文件,所以我没有在我的系统上使用现有的环境变量。

所以在我的.env我有一个名为 PROJ_CERT=/.keys/cert.pem 的变量,它与我的 .bash_profile 中的一个变量相冲突.

我把它改成了 CERT=...它现在正在工作。

关于docker - 无法读取已安装的卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51507073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com