Attach MSSQL_DB inside yml.file - sql-server

I have a project that runs in 3 Containers.
API-Container
Project-Container
MSSQL-Container
Since the Container is running with a new MSSQL database, I need to attach my DB to it.
So the question is, how can I attach it in my yml.file?
version: '3.4'
services:
levsundt.project:
ports:
- "32333:80"
image: ${DOCKER_REGISTRY-}levsundtproject
build:
context: .
dockerfile: ./LevSundt.Project/Dockerfile
environment:
"ASPNETCORE_ENVIRONMENT": "Development"
"ConnectionStrings:WebAppUserDbConnection": "Server=db;Database=LevSundtUsers;user id=web;password=webPassw0rd!; MultipleActiveResultSets=true;"
"LevSundtBaseUrl" : "http://levsundt.api"
depends_on:
- db
- levsundt.api
levsundt.api:
ports:
- "32330:80"
image: ${DOCKER_REGISTRY-}levsundtapi
build:
context: .
dockerfile: ./LevSundt.Api2/Dockerfile
environment:
"ASPNETCORE_ENVIRONMENT": "Development"
"ConnectionStrings:LevSundtDbConnection": "Server=db;Database=LevSundtDomain; user id=api;password=apiPassw0rd!; MultipleActiveResultSets=true"
depends_on:
- db
db:
image: "mcr.microsoft.com/mssql/server:2019-latest"
user: root
ports:
- "14330:1433"
environment:
MSSQL_SA_PASSWORD: "SqlPassw0rd!"
ACCEPT_EULA: "Y"
volumes:
- C:\Temp\SqlVolume\data:/var/opt/mssql/data
- C:\Temp\SqlVolume\log:/var/opt/mssql/log
- C:\Temp\SqlVolume\secrets:/var/opt/mssql/secrets
container_name: sql2019
hostname: sql1

Related

TDengine 3.0.2.2 create mnode execution stuck

Use docker-compose to deploy the TDengine Swarm cluster, there is no response after the execution of CREATE MNODE ON DNODE dnode_id, the command didn't execute correctly or report an error
Environment:
OS: docker image tdengine/tdengine:3.0.2.2
8G Memory, i5-1135G7, 512G SSD
TDengine Version: 3.0.2.2
Use docker-compose to build a Docker Swarm TDengine cluster
show mnodes and show dnodes are acting normal
There is no response after the execution of CREATE MNODE ON DNODE dnode_id, and there is no exception in the logs
I expect to be able to create mnode normally to achieve high availability of the cluster
Docker compose file:
version: "3.9"
services:
td-1:
build:
dockerfile: ./docker/tdengine.Dockerfile
args:
TAOSD_VER: 3.0.2.2
TZ: Asia/Shanghai
image: localhost:5000/kun/tdengine
networks:
- inter
environment:
TAOS_FQDN: "td-1"
TAOS_FIRST_EP: "td-1"
TAOS_SECOND_EP: "td-2"
volumes:
- taosdata-td1:/var/lib/taos/
- taoslog-td1:/var/log/taos/
deploy:
placement:
constraints:
- node.hostname==manager
td-2:
image: localhost:5000/kun/tdengine
networks:
- inter
environment:
TAOS_FQDN: "td-2"
TAOS_FIRST_EP: "td-1"
TAOS_SECOND_EP: "td-3"
volumes:
- taosdata-td2:/var/lib/taos/
- taoslog-td2:/var/log/taos/
deploy:
placement:
constraints:
- node.hostname==server-01
td-3:
image: localhost:5000/kun/tdengine
networks:
- inter
environment:
TAOS_FQDN: "td-3"
TAOS_FIRST_EP: "td-1"
TAOS_SECOND_EP: "td-2"
volumes:
- taosdata-td3:/var/lib/taos/
- taoslog-td3:/var/log/taos/
deploy:
placement:
constraints:
- node.hostname==server-02
adapter:
image: localhost:5000/kun/tdengine
entrypoint: "taosadapter"
networks:
- inter
environment:
TAOS_FIRST_EP: "td-1"
TAOS_SECOND_EP: "td-2"
deploy:
labels:
caddy_0: localhost:6041
caddy_0.reverse_proxy: adapter:6041
caddy_1: localhost:6044
caddy_1.reverse_proxy: adapter:6044
mode: global
placement:
constraints:
- node.role == manager
caddy-docker-proxy:
build:
dockerfile: ./docker/caddy-docker-proxy.Dockerfile
image: localhost:5000/kun/caddy-docker-proxy
networks:
- inter
ports:
- 6041:6041
- 6044:6044/udp
- 80:80
- 5188:5188
environment:
- CADDY_INGRESS_NETWORKS=inter
- CADDY_DOCKER_CADDYFILE_PATH=/etc/Caddyfile
volumes:
- caddy_data:/data
- /var/run/docker.sock:/var/run/docker.sock
deploy:
mode: global
placement:
constraints:
- node.role == manager
networks:
inter:
host:
external: true
volumes:
taosdata-td1:
taoslog-td1:
taosdata-td2:
taoslog-td2:
taosdata-td3:
taoslog-td3:
caddy_data:

Docker: React container can't fetch data from Express container without explicitly specify the ip address

I have a dockerized MERN application: React (Port 3000), Express (Port 4000) and MongoDB (Port 27017). I can access the MongoDB container with Express via "mongodb://root:root#database:27017" (database is the name of the container) but i can't access Express from React by "http://server:4000" or "http://localhost:4000" - i have to explicitly specify the ip address of my host system to access Express. This is my docker-compose.yml:
version: '3.9'
services:
database:
image: mongo:latest
container_name: database
ports:
- '27017:27017'
networks:
- mern
volumes:
- db_data:/data/db
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=root
restart: always
server:
build: ./server
depends_on:
- database
container_name: server
ports:
- '4000:4000'
networks:
- mern
volumes:
- ./server:/app
restart: always
client:
build: ./client
depends_on:
- server
container_name: client
ports:
- "3000:3000"
networks:
- mern
volumes:
- ./client:/app
stdin_open: true
restart: always
networks:
mern:
driver: bridge
volumes:
db_data:
driver: local
How can I use "http://server:4000" in my React application to access the Express API?

My dockerized project's expressjs server does not (randomly) send response to the client

I would be glad somebody helps me with this issue.
Actually my server express is randomly not able to send response to my react client app.
Here is morgan logs :
GET /api/comments?withUsers=true - - ms - -
GET /api/categories - - ms - -
POST /api/posts - - ms - -
GET /api/posts - - ms - -
Both of my server and client side apps are running in different docker containers.
Here is my docker-compose file :
version: '3'
services:
blog:
container_name: blog
build:
context: .
dockerfile: Dockerfile
depends_on:
- postgres
environment:
NODE_ENV: development
PORT: 4000
ports:
- '4000:4000'
volumes:
- .:/usr/src/app
client:
stdin_open: true
environment:
- CHOKIDAR_USEPOLLING=true
build:
dockerfile: Dockerfile
context: ./views
ports:
- '3000:3000'
volumes:
- ./views:/usr/src/app/views
postgres:
container_name: postgresql
image: postgres:latest
ports:
- '5432:5432'
volumes:
- db-data:/var/lib/postgresql/data
- ./sql_tables/tables.sql:/docker-entrypoint-initdb.d/dbinit.sql
restart: always
environment:
POSTGRES_USER: db_user_is_her
POSTGRES_PASSWORD: db_password_is_her
POSTGRES_DB: blog
pgadmin:
container_name: pgadmin
image: dpage/pgadmin4:latest
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: pgadmin_user_email_is_her
PGADMIN_DEFAULT_PASSWORD: pgadmin_password_is_her
PGADMIN_LISTEN_PORT: 80
ports:
- '8080:80'
volumes:
- pgadmin-data:/var/lib/pgadmin
depends_on:
- postgres
volumes:
db-data:
pgadmin-data:
app:
Thank you for your help

Deploying with docker-compose. Frontend is not reaching backend

So I'm running a web app which consist of 3 services with docker-compose.
A mongodb database container.
A nodejs backend.
A nginx container with static build folder which serves a react app.
Locally it runs fine and I'm very happy, when trying to deploy to a vps I'm facing an issue.
I've set the vps' nginx to reverse proxy to port 8000 which serves the react app, it runs as expected but I can not send requests to the backend, when I'm logged in the vps I can curl it and it responds, but when the web app sends requests, they hang.
My docker-compose:
version: '3.7'
services:
server:
build:
context: ./server
dockerfile: Dockerfile
image: server
container_name: node-server
command: /usr/src/app/node_modules/.bin/nodemon server.js
depends_on:
- mongo
env_file: ./server/.env
ports:
- '8080:4000'
environment:
- NODE_ENV=production
networks:
- app-network
mongo:
image: mongo:4.2.7-bionic
container_name: database
hostname: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME=...
- MONGO_INITDB_ROOT_PASSWORD=...
- MONGO_INITDB_DATABASE=admin
restart: always
ports:
- 27017:27017
volumes:
- ./mongo/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
networks:
- app-network
client:
build:
context: ./client
dockerfile: prod.Dockerfile
image: client-build
container_name: react-client-build
env_file: ./client/.env
depends_on:
- server
ports:
- '8000:80'
networks:
- app-network
networks:
app-network:
driver: bridge
volumes:
data-volume:
node_modules:
web-root:
driver: local

How to access linked docker container's host with react

My application has three containers: db, frontend-web(React), backend-api
How can I get my backend-api address in frontend-web
Here is my compose file
version: '2'
services:
db:
image: postgres
ports:
- "5432:5432"
web:
build: .
stdin_open: true
volumes:
- .:/usr/src/app
ports:
- "3000:3000"
environment:
- API_URL=http://api:8080/
links:
- api
depends_on:
- api
api:
build: ./api
stdin_open: true
volumes:
- ./api:/usr/src/app
ports:
- "8080:3000"
links:
- db
depends_on:
- db
I can't get the address both api and process.env.API_URL
Add the container name to the service description as follows:
api:
build: ./api
container_name: api
stdin_open: true
volumes:
- ./api:/usr/src/app
ports:
- "8080:3000"
links:
- db
depends_on:
- db
You can then use the container name as a host name to connect to. See https://docs.docker.com/compose/compose-file/#/containername
I am admitting that your server at the web container is just providing the static htmls and not working as a proxy for the api container server.
So, once that you mapped the ports to the host machine, you could use the host machines name/ip to find the api server.
If your host machine name is app.myserver.dev, in your API_URL env var you can use the config below and docker will do the work for you:
web:
build: .
stdin_open: true
volumes:
- .:/usr/src/app
ports:
- "3000:3000"
environment:
- API_URL=http://app.myserver.dev:8080/
links:
- api
depends_on:
- api

Resources