然后我在IIS Express上运行调试一切正常 .
我通过Ssh.NET库通过ssh连接到DB .
PasswordConnectionInfo connectionInfo = new PasswordConnectionInfo("here is remote ip", 22, "ssh login here", "password for ssh")
{
Timeout = TimeSpan.FromSeconds(30)
};
var client = new SshClient(connectionInfo);
client.Connect();
ForwardedPortLocal portForward = new ForwardedPortLocal("127.0.0.1", 22, "127.0.0.1", 3306);
client.AddForwardedPort(portForward);
portForward.Start();
services.AddDbContext<WhetherContext>(options =>
options.UseMySQL(Configuration.GetConnectionString("Server=127.0.0.1;Port=22;Database=MyDb;Uid=MySqlDatabaseLogin;Pwd=DbPassword;SslMode=none;")));
当我在docker-machine上运行它时,它会在尝试使用上下文时抛出异常 .
我使用Linux容器 . 可能导致什么?
UPD: Dockerfile
FROM microsoft/aspnetcore:2.0 AS base
RUN curl -sL https://deb.nodesource.com/setup_8.x
RUN bash -
RUN apt-get -y update
RUN apt-get install -y build-essential nodejs
RUN ln -s /usr/bin/nodejs /usr/bin/node
WORKDIR /app
EXPOSE 80
FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY *.sln ./
COPY WhetherService/WhetherService.csproj WhetherService/
RUN dotnet restore
COPY . .
WORKDIR /src/WhetherService
RUN dotnet build -c Release -o /app
FROM build AS publish
RUN dotnet publish -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WhetherService.dll"]
docker-compose.yml
version: '3'
services:
whetherservice:
image: alexandrs/whetherservice
build:
context: .
dockerfile: WhetherService/Dockerfile
docker-compose.ci.build.yml
version: '3'
services:
ci-build:
image: microsoft/aspnetcore-build:1.0-2.0
volumes:
- .:/src
working_dir: /src
command: /bin/bash -c "dotnet restore ./WhetherService.sln && dotnet publish ./WhetherService.sln -c Release -o ./obj/Docker/publish"
/etc/mysql/my.cnf file :
MySQL数据库服务器配置文件 . 您可以将其复制到以下选项之一: - “/etc/mysql/my.cnf”设置全局选项, - “〜/ .my.cnf”设置用户特定选项 . 可以使用程序支持的所有长选项 . 使用--help运行程序以获取可用选项列表,并使用--print-defaults查看它实际可以理解和使用的内容 . 有关说明,请参阅http://dev.mysql.com/doc/mysql/en/server-system-variables.html重要信息:可以覆盖此文件中的设置的其他设置!文件必须以“.cnf”结尾,否则将被忽略 . !includedir /etc/mysql/conf.d/!includedir /etc/mysql/mysql.conf.d/
netstat -tln :
1 回答
根据您提供的信息,您似乎忘记将远程mysql连接到您的映像 . 这样做的方法是打开远程服务器上的端口进行监听,然后在运行该程序的docker映像中,您需要使用conn字符串连接该远程服务器的主机名或IP地址 .