'Docker container cannot connect to Autonomous Database
I have a dotnet core project that connects to an Oracle Autonomous Datawarehouse. Running the project through Visual Studio works perfectly. I want to containerise the project, but whenever I run the container, it cannot connect to the ADW, failing with "TNS:could not resolve the connect identifier"
Here is my Dockerfile:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY backend.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c release -o /app
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 1522
COPY --from=build /app .
ENTRYPOINT ["dotnet", "backend.dll"]
In my project I created a top level folder named "tns". In there I have everything from the wallet file from my ADW. I have modified the sqlnet.ora file to look like this:
WALLET_LOCATION = (SOURCE = (METHOD = file) (METHOD_DATA = (DIRECTORY="tns")))
Here is my compose file:
version: '3.4'
services:
frontend:
image: pizzafrontend
build:
context: frontend
dockerfile: Dockerfile
environment:
- backendUrl=http://backend
ports:
- "5902:80"
depends_on:
- backend
backend:
image: pizzabackend
build:
context: backend
dockerfile: Dockerfile
ports:
- "5900:80"
- "1522:1522"
I tried adding an environment variable TNS_ADMIN="tns" or TNS_ADMIN="src/tns", neither of which made any difference. I am at my wits end with this, I feel I am so close to the answer, so any assistance welcome.
Solution 1:[1]
I think you are confusing 2 things:
- Simple communication between 2 containers through 2 ports with TCP or UDP protocol.
- Access to a frontend or a backend over HTTP (what you need)
In docker-compose, "frontend" and "backend" values the local IP of the containers, and thus can only be used for local communication between the exposed ports.
Thus you need one more variable: BACKEND_HOSTNAME. It will values "localhost" if you test locally, and the server IP or domain name if you deploy.
And thus backendUrl values http://$BACKEND_HOSTNAME:5900 if your backend is on port 5900.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ricola3D |
