neo4j & .NetCore Docker setup - docker

I want to setup my neo4j database and my .NetCore Web Api with Docker. I created the following docker-compose file :
version: '3.4'
services:
server:
image: ${DOCKER_REGISTRY-}server
network_mode: "bridge"
build:
context: .
dockerfile: Server/Dockerfile
stdin_open: true
tty: true
environment:
- CHOKIDAR_USEPOLLING=true
depends_on:
- neo4j
neo4j:
image: "neo4j:latest"
network_mode: "bridge"
ports:
- "7474:7474"
- "7687:7687"
volumes:
- $HOME/neo4j/data:/data
- $HOME/neo4j/logs:/logs
- $HOME/neo4j/import:/var/lib/neo4j/import
- $HOME/neo4j/plugins:/plugins
environment:
- NEO4J_AUTH=neo4j/admin
Within my .NetCore Server I check whether I can reach the neo4j address (172.17.0.3:7474), which works. Connecting to the Neo4J Database does not work with the following code :
_client = new GraphClient(new Uri("http://172.17.0.3:7474/db/data/"), "neo4j", "admin");
_client.Connect();
The error message is :
System.Exception: 'Received an unexpected HTTP status when executing the request.
The response status was: 404 Not Found

The library doesn't fully support Neo4j 4.x yet -still in development-.
You can either use an older image of Neo4j (using Neo4j:3.5.19 connects successfully), or you can use a different driver.

Related

Unable to establish communication between API and WEB service in Docker

I am trying my hands-on on Docker and am a newbie to this technology. Here's an issue I am stuck since long:
I have an application composed of DJango REST Framework, Angular and MySQL as database. I am trying to dockerize each of these component and execute using docker-compose
Here is my docker-compose.yml file:
version: '3'
services:
db:
image: mysql:5.7.33
container_name: db
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ******
MYSQL_DATABASE: database
volumes:
- mysql_db:/var/lib/mysql
api:
build:
context: ./api
dockerfile: Dockerfile
container_name: api
volumes:
- /api36:/home/api/api36
ports:
- "8010:8010"
depends_on:
- db
ui:
build:
context: ./ui
dockerfile: Dockerfile
volumes:
- /ui:/ui
container_name: ui
ports:
- "4201:4201"
depends_on:
- db
volumes:
mysql_db:
I updated settings.py file to point to db as HOST in DATABASES, so I am able to have a communication between my DB and API calls.
However, when I load the UI I face a failure saying: Failed to load resource: net::ERR_NAME_NOT_RESOLVED. I had added serviceUrl as http://api:8010/ in my environment.ts file. As api is name of my API service, I expected that docker-compose will establish communication internally, but looks like I am missing something. Also, I am able to get the expected behavior when I add ip of the machine in environment.ts file.
Can someone please help me out on this?
The way I bring up and execute all the containers is docker-compose up.
Thanks in advance!

NetCore Docker Application with connection refused

I have two containers (both .net-core), a Web Application and a Web API, the Web Application can be accessed from the host machine using http://localhost:51217, however I can't access the Web API using http://localhost:51218, I got the connection refused, in order to access the Web API, I had to change the Kerstel URL configuration from ASPNETCORE_URLS=http://localhost to ASPNETCORE_URLS=http://0.0.0.0, so webserver listen all IP's.
Any clue why the localhost works for the Web App but not for the Web API, although both have different port mapping.
See below my docker-compose working fine, if I change the API to ASPNETCORE_URLS=http://localhost, I will get connection refused. The docker files exposes port 80.
version: '3.5'
services:
documentuploaderAPI:
image: ${DOCKER_REGISTRY-}documentuploader
container_name: DocumentUpoaderAPI
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0
networks:
- doc_manager
ports:
- "51217:80"
volumes:
- ${APPDATA}/Microsoft/UserSecrets/:/root/.microsoft/usersecrets
- ${APPDATA}/ASP.NET/Https/:/root/.aspnet/https/
- c:\azurite:/root/.unistad/
build:
context: .
dockerfile: DocumentUploader/Dockerfile
documentmanagerAPP:
image: ${DOCKER_REGISTRY-}documentmanager
container_name: DocumentManagerApp
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://localhost;http://localhost
networks:
- doc_manager
ports:
- "51218:80"
volumes:
- ${APPDATA}/Microsoft/UserSecrets/:/root/.microsoft/usersecrets
- ${APPDATA}/ASP.NET/Https/:/root/.aspnet/https/
build:
context: .
dockerfile: Document Manager/Dockerfile
networks:
doc_manager:
name: doc_manager
driver: bridge
Any idea why localhost doesn't work for the API? Any suggestion also how can I trace or sniff the communication from browser until the web server in the container?
You can find below the docker networking design, which may help on my question.

understanding Docker compose mongodb and rails application

there is ruby on rails application which uses mongodb and postgresql databases. When I run it locally everything works fine, however when I try to open in a remote container, it throws error message
2021-03-14T20:22:27.985+0000 Failed: error connecting to db server: no reachable servers
the docker-compose.yml file defines following services:
redis mongodb db rails
I start remote containers with following command:
docker-compose build - build successful
docker-compose up -d - containers are up and running
when I connect to the rails container and try to do
bundle exec rake aws:restore_db
error mentioned above is thrown. I don't know what is wrong here. The mongodb container is up and running.
the docker-compose.yml is mentioned below:
version: '3.4'
services:
redis:
image: redis:5.0.5
mongodb:
image: mongo:3.6.13
volumes:
- mongo-data:/data/db
db:
image: postgres:11.3
volumes:
- db-data:/var/lib/postgresql/data
rails:
build: .
image: proj:latest
depends_on:
- db
- mongodb
- redis
volumes:
- .:/proj
ports:
- "3000:3000"
tty: true
stdin_open: true
env_file:
- .env/development.env
volumes:
db-data:
mongo-data:
this is how I start all four remote containers:
$ docker-compose up -d
Starting proj_db_1 ... done
Starting proj_redis_1 ... done
Starting proj_mongodb_1 ... done
Starting proj_rails_1 ... done
please help me to understand how remote containers should interact with each other.
Your configuration should point to the services by name and not to a port on localhost. For example, if you ware connecting to redis as localhost:6380 or 127.0.0.1:6380, now you need to use redis:6380
If this is still not helping, you can try to add links between containers in order the names given to them as services to be resolved. So the file will look something like this:
version: '3.4'
services:
redis:
image: redis:5.0.5
networks:
- front-end
links:
- "mongodb:mongodb"
- "db:db"
- "rails:rails"
mongodb:
image: mongo:3.6.13
volumes:
- mongo-data:/data/db
networks:
- front-end
links:
- "redis:redis"
- "db:db"
- "rails:rails"
db:
image: postgres:11.3
volumes:
- db-data:/var/lib/postgresql/data
networks:
- front-end
links:
- "redis:redis"
- "mongodb:mongodb"
- "rails:rails"
rails:
build: .
image: proj:latest
depends_on:
- db
- mongodb
- redis
volumes:
- .:/proj
ports:
- "3000:3000"
tty: true
stdin_open: true
env_file:
- .env/development.env
networks:
- front-end
links:
- "redis:redis"
- "mongodb:mongodb"
- "db:db"
volumes:
db-data:
mongo-data:
networks:
front-end:
The links will allow for a hostnames to be defined in the containers.
The link flag is legacy, and in new versions of docker-engine it's not required for user defined networks. Also, the links will be ignored in case of docker swarm deployment. However since there are sill old installations of Docker and docker-compose, this is one thing to try in troubleshooting.

Fail to resolve docker compose service name from front end

Hi I'm new to using docker for development. I'm trying to communicate from frontend (react) to the backend (express.js) here.
I have enabled cors as well, I'm getting an error saying net::ERR_NAME_NOT_RESOLVED when trying to fetch from the back end using the url http://backend:4001,
but it's working when I use the docker internal IPAddress, like: http://172.18.0.3:4001.
Following is my docker-compose.yml file.
Please advise on getting this working, thanks.
version: "3"
services:
backend:
build: ./api
volumes:
- ./api:/usr/src/api
ports:
- 6002:4001
depends_on:
- database
database:
image: mongo:4.0.15-xenial
ports:
- 27018:27017
frontend:
build: ./app
volumes:
- ./app:/usr/src/app
ports:
- 6001:3000
links:
- backend
depends_on:
- backend
It will not work, because your browser(internet client) is not part of docker stack network, you have to configure you frontend service to connect to http://localhost:6002 instead of http://backend:4001

How to communicate between two docker containers (mssql and .net core app)

I have the following issue: I have the following docker-compose file
version: "3"
services:
web:
build: .
ports:
- "8000:80"
links:
- my-special-db
networks:
- demo-net
my-special-db:
image: "microsoft/mssql-server-windows-developer"
ports:
- "1433:1433"
environment:
- ACCEPT_EULA=Y
- sa_password=demo
networks:
- demo-net
networks:
demo-net:
driver: nat
In the appsettings.Docker.json I have the following connection string: "ConnectionStrings": { "DefaultConnection": "Server=my-special-db;Database=ContosoUniversity3;Trusted_Connection=True;MultipleActiveResultSets=true" }
I've tried passing also the password, it doesn't work.
What I'm doing wrong?
You need to add both services in a common network.
Please rede this document: Docker Networks
In each of your services:
networks:
- sql-net
In the end of the compose file:
networks:
sql-net:
driver: bridge
Then you'll be able to connect to the database through its container name, in your case my-special-db
EDIT 1 - Network Drivers under windows
The error reported by the OP suggests that it's running Windows 10. There is an open bug for it here
There are reports that using transparentdriver might work:
networks:
sql-net:
driver: transparent
EDIT 2 - Links Option
You can also try using the legacy Link feature. Add this to the web container:
web:
links:
- my-special-db

Resources