The mysql server is running on top of docker with Ubuntu OS.
I only want to allow the DB connections from the Ubuntu host machine and disallow all connecitons from the rest of world for the security reason.
Related
I installed mongodb inside docker container in oracle linux virtual machine. I need to connect this mongodb with mongodb compass. I don't have user account for mongodb and don't have mongod config file in the docker or in virtual machine.
More Information:
I created oracle linux virtual machine from oracle cloud. Then, using my current system's(windows) command prompt, I connected to that machine. Through that, I created a docker container inside the virtual machine. And then, I installed mongodb-6.0.2 inside the docker container. Now, when I try to connect this mongodb database(in virtual machine) to the mongodb compass, It is connecting to my current system's mongodb database(which was installed before the creation of this virtual machine). I also attached the screenshot of my virtual machine's docker and mongodb's information in cmd.
Here is the screenshot of ip of my docker inside the virtual machine
Can anyone solve this issue and tell me how can I make connection of this virtual machine database to mongodb compass?
If wanting to use Compass from Windows and connect to a MongoDB container running an Oracle cloud compute instance, you'll need to make sure networking allows for connections to port 27017 via an ingress rule in your network security group.
Another option is to use port forwarding over ssh.
I have Ubuntu in a Window (which I installed from Microsoft Store). In this Ubuntu, I have a Ruby web app in this Ubuntu which connects to Postgres in my Window (not Ubuntu). This is my database.yml (/apps/appname/config/)
development:
adapter: postgresql
encoding: unicode
pool: 5
host: localhost
port: 5432
database: xxx
username: postgres
password:
All these I have setup accordingly. When I run rails server, the web app starts and listening to localhost:3000. When I open the browser at localhost:3000, I get this error below:
> PG::ConnectionBad at /sign_in could not connect to server: Connection
> refused Is the server running on host "localhost" (127.0.0.1) and
> accepting TCP/IP connections on port 5432?
I have troubleshoot by running psql and I can connect to the database at port 5432.
Server [localhost]:
Database [postgres]: xxx
Port [5432]:
Username [postgres]:
Password for user postgres:
psql (10.15)
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.
How do I troubleshoot this further? I realize that I didn't run Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux in Windows PowerShell in Window before I install Ubuntu. Could the issue due to this step which I miss out?
First, I'm assuming this is a WSL2 instance, not WSL1.
WSL2 instances really do run in a VM. The "VirtualMachinePlatform" component is a subset of Hyper-V. The WSL2 instances are running NAT'd (not bridged) behind their own virtual NIC vEthernet (WSL).
localhost to the WSL2 instance points to the virtual interface, not to the Windows host. On the flip side, Windows does attempt to detect ports bound inside a WSL2 instance and allow Windows applications (such as a web-browser) access to the services on those ports via localhost. However, this seems to break down for some people every so often, requiring a wsl --shutdown of the VM in order to restore the functionality.
So yes, you can access the Rails app (running in WSL) using your web browser (running in Windows) at localhost. However, you can't access the Postgres server running in Windows from the Rails server running in WSL2 via localhost.
Or at least you shouldn't. I'm surprised that the psql command seems to be working. Is it that:
psql is running under WSL? (shouldn't work via localhost)
Or perhaps you mean that you are running psql from PowerShell or cmd? That would of course work via localhost
Or perhaps the psql command is in the Windows path that gets propagated to WSL? That would also allow it to work via localhost.
But ultimately, what you should need for accessing the Windows Postgres server from within WSL is to simply use a Windows IP or address pointing to it. I've detailed some options in this answer a few days ago. But short answer:
Use mDNS, the ".local" domain. If your hostname is stevesdesktop, then try replacing localhost in your database.yml with stevesdesktop.local.
If that doesn't work, use the Windows IP directly.
Or edit /etc/hosts with the IP and a name to assign.
When you say Ubuntu in a Window I suppose you have a Ubuntu running on a VM on your Windows OS.
From the Ubuntu system point of view, localhost is it's own IP, not the one where PostgreSQL is running.
The virtualization engine usually assigns an IP to the VMs running on it, depending on the configuration of the engine, the network configuration of the VM in it and the network configuration of the system inside the VM (usually, plain DHCP). I'd consider looking at all of them.
If you are creating an internal network (which is the default on some virtualization engines and usually is in the range 192.168.122.0/24), the IP of your host (the system running in the hardware, the one running the virtualization engine, the one running the PostgreSQL server, not the VM) inside this private network will probably be 192.168.122.1. That will be the IP where the VM will be able to connect to the PostgreSQL server.
Note: You'll need to ensure PostgreSQL is started after the virtualization engine starts the virtual network, so PostgreSQL will open the port on this network, too (well, I don't know very much about how Windows handles opening TCP ports, but it's a good practice).
Edit
While the above commands and tips are still useful, Ubuntu in a Window runs WSL, which is not a VM engine. As stated in the WSL FAQs:
WSL shares the IP address of Windows, as it is running on Windows. As such you can access any ports on localhost e.g. if you had web content on port 1234 you could https://localhost:1234 into your Windows browser.
the network stack is shared, so localhost and 127.0.0.1 are good hosts to connect applications across Windows and Linux apps. Also, as stated in the FAQs, your firewall might be blocking network connections. If disabling the firewall solves the problem, you'll need to explicitly allow the desired connection.
I am trying to add an existing MySQL database as a source database to a docker container running Apache Superset. The MySQL database that I am trying to add is not running in a docker container. It's an existing MySQL database running on a Windows machine.
I've added mysqlclient==1.4.6 to requirements.txt. The error message seems to indicate that the driver is installed.
I've used mysql://user:password#127.0.0.1:3306/database_name and mysql://user:password#localhost:3306/database_name
The error I get is:
"ERROR: Connection failed, please check your connection settings."
I am using image: apache / 'incubator-superset' v. 0.36.0
Are there any settings or config that needs to be changed to be able to communicate to an external database from within a running docker container?
So I figured it out. For Windows, run ipconfig (maybe ifconfig linux, mac) in terminal/powershell and check what ip address docker ethernet port is using (listed as WSL), let's say ip is: 172.x(x).x(x).x(x). Then configure connection string with ip address on docker ethernet port as follows: 'mysql://user:password#172.x(x).x(x).x(x):3306/database_name'.
Follow-up question if anybody knows: How can I connect my docker container running apache/superset to another server/ip address on my local network running a MySQL server? In other words I want to connect the apache/superset app that is running on my computer in a docker container, to another computer on my local network that is running a MySQL server. The MySQL sever is not in a docker container.
maybe the steps of this blog can help.
If your mysql is in other docker it it is not 127.0.0.1 and in addition if you don't want the requirements to be updated every time that you git pull a new docker, it is better to use the requirements-local.txt
You should be able to do that but your MySQL has to have external IP that you can access from your Supserset Machine. First do a telnet to see if you can listen from port 3306 to that machine and if you can Supserset should work with very similar URI that you have.
I run docker on windows. I have a docker container running a python application that needs a database connection.
Installing a DB on my machine and connecting to it via "docker.for.win.localhost" in my container works fine.
Now I want to connect to a database running on a server that is available over my local network. I can't seem to connect to it from inside my docker container. I don't quite understand how I can proxy the server to my container. The error indicates that it can't establish a connection to this server:
(psycopg2.OperationalError) could not connect to server: No route to host
Is the server running on host "XX.XXX.XX.XX" and accepting
TCP/IP connections on port 5555?
I'm sure this is supposed to work somehow, right?
you can add IP of host to the container
docker run --add-host="yourhost:IPOFTHEHOST"
and yourhost will be connected to host
I have a web application running within docker but the MYSQL database is running on different host and port ( outside docker environment)
Its the legacy database and we have decided not to migrate it to docker environment.
I am not able to telnet from within docker shell to MYSQL host/port
Can any one help me with an example docker-compse.yml showing how an app within docker can connect to an external MYSQL or any service running on an external host and port.