Issue on connecting local mysql-workbench with docker mariadb - docker

Currently I'm facing an issue trying to connect to my mariadb database running in an docker-container.
My Local Information:
OS: Windows 10
Docker-Toolkit
Trying to connect from MySql Workbench
Workbench config
Docker ps returns following:
Docker List
Testing the connection I only get the error message "Failed to Connect to MySQL at 127.0.0.1:3306 with user root. Can't connect to MySQL server on '127.0.0.1' (10061)".
Error Message
Trying to connect using MySql-Workbench from my virtual machine (Ubuntu) it works without problems.
Does someone have an idea how to solve that issue?
Update:
I started the docker container using docker-compose:
mysql:
image: mariadb:10.1
ports:
- "127.0.0.1:3306:3306"
environment:
MYSQL_DATABASE: databasename
MYSQL_ROOT_PASSWORD: pw
volumes:
- myproject-mysqldata:/var/lib/mysql
networks:
- back
logging:
options:
max-size: "25m"
max-file: "4"
Update 2:
Also tried to connect using Squirel with MariaDB Driver. Also doesn't work. It seems, that windows can't find the 127.0.0.1:3306.
"Telnet 127.0.0.1 3306" also responded with a not found message.
What I'm doing wrong here?
Is it maybe due to the docker-toolbox and Virtualbox usage?
Solution:
Hey all, thank you for your help. I tried to put my won information into a blog-post hoping that it can help someone: Solution

What I'm doing wrong here? Is it maybe due to the docker-toolbox and Virtualbox usage?
One of the Cons mentioned here: Should You Install Docker With the Docker Toolbox or Docker for Mac / Windows? states:
Docker Toolbox
Cons
Not a native solution, so you’ll need to access your Docker Machine’s IP address if you’re developing web apps. Example: 192.168.99.100 instead of localhost.
and I think the same is also mentioned here: Docker Toolbox - Localhost not working
In Toolbox, nothing will be localhost, and will be 192.168.99.100 by default, since it's running a Linux VM in VirtualBox.

Related

Docker app to host mysql connection not working (host os & image = windows)

My app from container wants to access Mysql from host machine, but is not able to connect. I googled a lot and tried many solutions but could not figure the error, could you please help me on this.
It is a windows image
IIS Website works
Website pages that use DB Connection does not work
Mysql DB is install in local machine (same pc where docker desktop is installed in)
Connection string in app uses 'host.docker.internal' with port 3306.
Tried docker uninstall, reinstall, image prune, container prune, WSL stop and start, host file commenting for below lines:
192.168.1.8 host.docker.internal
192.168.1.8 gateway.docker.internal
Below is the ipconfig from container
Nslookup and Ping commands:
network LS:
Docker Compose:
version: "3.9"
services:
web:
container_name: dinesh_server_container
image: dinesh_server:1
build: .
ports:
- "8000:80"
- "8001:81"
volumes:
- .\rowowcf:c:\rowowcf
- .\rowowcf_supportfiles:c:\rowowcf_supportfiles
- .\rowocollectionsite:c:\rowocollectionsite
environment:
TZ: Asia/Calcutta
Build image uses: FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8
Host OS: Win 10 Pro 10.0.19043 Build 19043
HyperV is enabled too.
Tried the below too:
extra_hosts:
- "host.docker.internal:host-gateway"
Since it is on windows OS - host network mode is not supported (per my research)
EDIT:
MYSQL Bind Address is 0.0.0.0:
Maybe the problem is not directly related to docker but to mysql.
Please, try making your local mysql database listen in all the network interfaces of your host: by default it only listens in 127.0.0.1 and for this reason perhaps docker is unable to connect to it.
I am not sure about how to do it in Windows but typically you need to provide the value 0.0.0.0 for the bind-address configuration option in mysqld.cnf:
bind-address = 0.0.0.0
Please, consider review as well this article or this related serverfault question.
From a totally different point of view, I found this and this other related open issues in the Docker for Windows repository that in a certain way resembles your problem: especially the first one provides some workaround for the problem, like shutting down the wsl backend and restarting the docker daemon. I doesn't look like a solution to me, but perhaps it could be of help.

Access to Cosmos db emulator on local machine from Linux docker

I little confused with Linux docker and cosmos db emulator. I have an emulator installed on my local machine. On my Windows 10 I have a Linux docker container with Web API ASP.NET core application. When I try to get access from container to cosmos db I get an exception -> HttpRequestException: Connection refused.
In C# code I get needed options like AuthKey and Uri to database from environment variables. Looks like I have an issue with network between container and localhost but I can not understand how I can connect these.
Below provided docker-compose.yml and docker-compose.override.yml files.
event.webapi:
container_name: event.webapi
image: '${DOCKER_REGISTRY-}eventwebapi'
environment:
**- AzureCollectionName=Events
- AzureDatabaseName=EventsDatabase**
build:
context: .
dockerfile: src/Services/Event/Event.WebApi/Dockerfile
``` docker-compose.override.yml
event.webapi:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_HTTPS_PORT=44378
**- AzureEndpointUri=https://127.0.0.1:8081
-AzurePrimaryKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==**
ports:
- "53753:80"
- "44378:443"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
You can't access vm host from docker container inside by setting https://127.0.0.1:8081 directly.
Please refer to this document, and try to set host.docker.internal:8081 to access vm host.
The host has a changing IP address (or none if you have no network
access). From 18.03 onwards our recommendation is to connect to the
special DNS name host.docker.internal, which resolves to the internal
IP address used by the host. This is for development purpose and will
not work in a production environment outside of Docker Desktop for
Windows.
Cosmos DB emulator needs installed SSL certificate,according to this link. For .net runtime, you could access the certificate directly from the Windows Certificate Store.
However, you run the .net code in linux docker image.So my idea is exporting SSL certificate following these steps.
Save it in the specific path on the host and mounting host directories.Please refer to this guide.

How should I connect to a container using the host rather than the service name?

I'd like to be able to connect to localstack using the host rather than the service name. I have added the localstack image to my docker-compose file and set network_mode: "host". I can connect to http://localhost:8080 from my other containers. But, I can not connect to: http://localhost:8080 from my host machine. How can I connect to a container using localhost rather than the service name? Not sure if I have misunderstood what network_mode: "host" does.
version: "3"
services:
localstack:
image: localstack/localstack:latest
network_mode: "host"
ports:
- "4567-4584:4567-4584"
- "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
environment:
- AWS_REGION=us-east-1
- SERVICES=sqs
Problem is I'm using CircleCI to run some component tests, but it seems that in CircleCI you can only reference other services on localhost and not via the service name. This means there are some difference between my local environment and test environment configs. I tried running docker-compose in CircleCI but it seems to freak out locally when doing that. So I wanted to see if I can reference localhost between services in docker-compose.
This happens because Docker for Mac runs inside a virtual machine using the xhyve hypervisor not natively on macOS.
When you run the container with net=host you are actually using the network of the VM and not the one from your local machine.
This is a known limitation of Docker for mac given the nature of how it works.
The only way to access a container is by using port mapping, so if you remove the network_mode:"host" from your docker-compose file it should work as you are already mapping ports.

Set docker toolbox container to receive information sended to host

I have a prototype that sends information to the host machine, and with Docker for Windows, the container grabs that information and everything works fine.
My docker-compose.yml file:
version: '3'
services:
middleware:
container_name: middleware
image: hyperloopupv:middleware
build: './receta'
ports:
- "5672:5672"
- "15672:15672"
- "1338:1338/udp"
- "5556:5556/udp"
But others from my team are using Docker Toolbox, and Docker Toolbox can not use localhost. I have tried to send the information from the prototype to the IP of the container(192.168.99.100), but the packets are lost.
Is there a way, that my team(using Docker Toolbox) and I(using Docker for Windows) can get this running without problems with the same compose file?
Thanks
Docker Desktop and Toolbox are completely different products. Docker Desktop runs on Hyper-V, Docker Toolbox on Virtualbox. Desktop is the actual product, Toolbox is the “legacy desktop solution”.
It is possible to manipulate its IP address. If you look a the docs under ‘Options’ you find an option called virtualbox-hostonly-cidr that you can use to manipulate the IP address when you create a new machine. But before you try this notice that it is called ‘hostonly’. This means it uses the Virtualbox Host-Only adapter and “the virtual machines cannot talk to the world outside the host since they are not connected to a physical networking interface” (from the Virtualbox docs).
So unfortunately it seems there is no simple solution to your problem.

How to get docker oracle container ip into the java application using docker-compose?

The below code iam using in docker-compose:
integration_test:
image: service:1.0.0
volumes:
- .:/service
links:
- oracle_container
# used volumes_from as workaround to wait until the following containers to start
volumes_from:
- oracle_container
container_name: integration_test
tty: true
environment:
USER: go
command: ["mvn clean install -DskipTests"]
oracle_container:
image: inmage_name:1.0.0
container_name: oracle_container
ports:
- "49161:1521"
I want to make the both containers talk application-->oracle
Both containers are running in same machine and i used the below jdbc string to connect the oracle via application,
jdbc:oracle:thin:#localhost:49161/xe
But iam not able to connect the oracle and its throwing SQLRecoverable Exception.
As per my understanding, this comes under Docker Networking and I have used links to connect two containers. but this issue is with the connection string and more specifically ip of the oracle container.
Can someone help on this issue?
You need to use
jdbc:oracle:thin:#oracle_container:1521/xe
In docker-compose each container can reach other on their service name of the container name. You should not used the host ports instead the container port only

Resources