I am using a docker-compose to create two containers. One is for Microsoft SQL Server and the other one is for WebApp.
The WebApp container is exiting with exit code 139.
SQL container is running and my required schema is also available I checked by connecting through SSMS but when my application is trying to access the database I am getting an unhandled exception saying:
Unhandled exception. System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)
My docker-compose file looks like this:
version: "3.4"
services:
sqldb:
restart: always
user: root
container_name: sqldb
image: mcr.microsoft.com/mssql/server
ports:
- 1433:1433
volumes:
- sqlvolume:/var/opt/mssql/data
environment:
SA_PASSWORD: "testpass"
ACCEPT_EULA: "Y"
webapi:
image: "${DOCKER_REGISTRY-}WebApi"
ports:
- 80:80
environment:
- Database=Server=sqldb,1433;Database=Emp;User Id=sa;Password=testpass;
depends_on:
- sqldb
build:
context: .
dockerfile: webapi/Source/Dockerfile
volumes:
sqlvolume:
driver: local
How to connect SQL server container with application container.
Related
I have launched a SQL Server Express container via docker-compose. This launches all fine and I can connect with my locally installed SQL Management Studio using the credentials. But when I try to connect from R, I get the following error:
Error: nanodbc/nanodbc.cpp:1021: 01000: [Microsoft][ODBC SQL Server
Driver][DBNETLIB]SQL Server does not exist or access denied.
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen
(Connect()).
docker-compose.yml
services:
sql-server:
image: mcr.microsoft.com/mssql/server:2019-latest
restart: unless-stopped
hostname: sql-server
container_name: sql-server
ports:
- "1433:1433"
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=foobar
- MSSQL_PID=Express
volumes:
- mssqldata:/var/opt/mssql
volumes:
mssqldata:
I use the following connection code in R:
conn <- DBI::dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "localhost\\SQLEXPRESS",
UID = "sa",
PWD = "foobar"
)
Is anybody aware of a setting within SQL Server Express that needs to be set to allow access from R or something along those lines?
I have asp.net core web and API running ok when published in the IIS server
I am trying to dockerize it using visual studio 2022
The web project has an appsetting.json file, that contains the API URL to communicate with but it always gives an error while debugging with any action required to connect to API
the Line contains the API URL in the appsetting.Json is :
"ApiUrl": "http://[service name]:3002/api/",
Errors:
connection failed because the connected host has failed to respond "when using the service name"
connection refused "when using the localhost"
no such host "when using the IIS published API URL"
The docker-compose file is :
version: '3.4'
services:
pms.pl:
image: ${DOCKER_REGISTRY-}pmspl
build:
context: .
dockerfile: PMS.PL\Dockerfile
ports:
- "3001:80"
- "3003:443"
networks:
- strnet2
extra_hosts:
test3: 192.168.1.x
pms.api:
image: ${DOCKER_REGISTRY-}pmsapi
build:
context: .
dockerfile: PMS.API\Dockerfile
ports:
- "3002:80"
- "3004:443"
networks:
- strnet2
extra_hosts:
test3: 192.168.1.x
networks:
strnet2:
driver: nat
I have an ASP .NET app in a container that I am trying to connect to a mssql container (running in the same network) but no matter what I change in the connection string, my app still crashes Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904): Login failed for user 'sa'.
My docker file looks like this:
services:
dotnet_be:
build: "./"
ports:
- "5000:80"
depends_on:
- db
db:
image: "mcr.microsoft.com/mssql/server"
environment:
SA_PASSWORD: "Your_password123"
ACCEPT_EULA: "Y"
And my connection string looks like this:
"ConnectionString": "Server=db;Database=DeskBooking;User id=sa;Password=Your_password123;Trusted_Connection=False; MultipleActiveResultSets=true; Integrated Security=False;"
I am using db as server as both services are within the same network and they are accessible via the container name.
Try this
services:
db:
image: mcr.microsoft.com/mssql/server
container_name: db
environment:
- SA_PASSWORD=Your_password123
- ACCEPT_EULA=Y
restart: always
ports:
- "1433:1433"
dotnet_be:
build: "./"
ports:
- "5000:80"
depends_on:
- db
Note: No double quotes around password, eula and image.
Connection string is thesame
Probably you do not respect password security requirements.
Try this changes:
services:
dotnet_be:
build: "./"
ports:
- "5000:80"
depends_on:
- db
networks:
- my-network
db:
image: "mcr.microsoft.com/mssql/server:2019-latest"
container_name: db
ports:
- "1433:1433"
environment:
MSSQL_SA_PASSWORD:1hisIsStrongPwd!!
ACCEPT_EULA:Y
networks:
- my-network
"ConnectionString": "Server=db;Database=DeskBooking;User id=sa;Password=1hisIsStrongPwd!!;Trusted_Connection=False; MultipleActiveResultSets=true; Integrated Security=False;"
Check for errors with docker logs containerId, where containerId is the container from docker ps.
I have a docker container (Windows 10) running on a new docker network I've defined. The container runs a pentaho transformation that tries to connect to an OpenEdge database.
Within my transformation set up, I have the following DB connection parameters:
#Connection URL
jdbc:datadirect:openedge://<machine_name>:<machine_port>;databaseName=<db_name>;user=<user_name>;password=<pass_word>
#Driver
com.ddtek.jdbc.openedge.OpenEdgeDriver
#User
user_name
#Pass
password
I have the correct drivers in the pentaho lib folder with the correct permissions.
I'm running the transformation from docker-compose and successfully connecting to a mysql DB in another container:
version: "2"
services:
db:
image: mysql:latest
container_name: my-pdi-mysql
networks:
- my-pdi-network
environment:
- MYSQL_ROOT_PASSWORD=tbitter
- MYSQL_DATABASE=mysql-db
ports:
- "3307:3306"
volumes:
- ./goldbi:/var/lib/mysql
pdi:
image: my-pdi-image-with-pan:latest
container_name: my-pdi-container
networks:
- my-pdi-network
volumes:
- C:\Docker-Pentaho\resource:/home/pentaho/data-integration/resources
#entrypoint:
# - C:\Docker-Pentaho\docker-entrypoint-2.sh
networks:
my-pdi-network:
How do I also connect to a DB on an external machine on the same network as the host from my container? I've done a lot of 'googling' on this but I'm a bit confused!
Any help would be greatly appreciated.
Thanks.
I'm trying to connect a ASP.NET Core container to PostgreSQL official container using Docker-Compose, I've name my container as aspnetcore-postgres and it contains in the configuration the connection string points to the PostgreSQL container as:
User ID=postgres;Password=5432;Host=localhost;Server=localhost;Port=5432;Database=ApplicationDbContext;Pooling=true;
And I use the following compose file for connection:
version: '2'
services:
web:
image: aspnetcore-postgres
ports:
- "5000:5000"
networks:
- aspnetcoreapp-network
postgres:
image: postgres
environment:
- "POSTGRES_PASSWORD: 5432"
networks:
- aspnetcoreapp-network
ports:
- "5432:5432"
networks:
aspnetcoreapp-network:
driver: bridge
Whenever I try to run docker-compose up, the web application can't recognize the database container. Eventually, I only see the Postgres container in the network not the web application container. I'm using Docker for Windows RC4.
Anyone can recognized that where I'm doing the wrong step?