Then I run debug on IIS Express all is going OK.
I make connection to DB over ssh by Ssh.NET library.
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;")));
When I run it on docker-machine, it throws exception when try to use context.
I use Linux containers. What may cause that?
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:
The MySQL database server configuration file.
You can copy this to one of: - "/etc/mysql/my.cnf" to set global options, - "~/.my.cnf" to set user-specific options.
One can use all long options that the program supports. Run program with --help to get a list of available options and with --print-defaults to see which it would actually understand and use.
For explanations see http://dev.mysql.com/doc/mysql/en/server-system-variables.html
- IMPORTANT: Additional settings that can override those from this file! The files must end with '.cnf', otherwise they'll be ignored.
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
netstat -tln :
Dockerfile
and if applicable command or docker compose file – Mike Tung