【发布时间】:2018-07-14 00:43:38
【问题描述】:
然后我在 IIS Express 上运行调试一切正常。
我通过 ssh.NET 库通过 ssh 连接到数据库。
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 容器。是什么原因造成的?
更新: 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 文件:
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:
【问题讨论】:
-
你查过mysql绑定了哪个ip吗? 127.0.0.1 或 docker 实例 ip
-
这可能是权限问题,您是否授予了对docker容器IP地址的访问权限?
-
你是如何运行 docker 的?显示
Dockerfile和如果适用的命令或 docker compose 文件 -
@MikeTung 添加了
-
@KamranShahid 我没有找到任何解决方案。经过一些尝试,我在 PostgreSQL 上......并且没有再次尝试 MySQL
标签: c# mysql docker asp.net-core ssh.net