Connecting a Docker container to a remote MySQL Database
I've set up a Docker container for the app using Centos 6.x, but can't get the MySQL connection working. The container has MySQL installed and the mysqld running.,With the container running, I can execute the following command (outside the container) to show databases on the remote DB:,The Docker works like a virtual machine. It has a local storage and a local environment. When you connect to 127.0.0.1 from the Docker it tries to connect to this Docker (not to local machine where the Docker was runned) because the localhost for the Docker is the Docker.,I'm working to containerize a Django 1.5.x application that connects to a MySQL DB on a separate server via ODBC:
I'm working to containerize a Django 1.5.x application that connects to a MySQL DB on a separate server via ODBC:
[mysql_default] database = DB_NAME driver = /usr/lib64 / libmyodbc5.so server = REMOTE_DB_SERVER user = DB_USER password = DB_USER_PWD port = 3306
From a container perspective, localhost or 127.0.0.1 always belong to the containers virtual network interface, just as it would be use on any physical host. All containers get its own local ip and a host name that can be used to resolve the route to the container. If you expose a port, like you do with the web service, you bind the internal port (80 in your case) with the host machine port (8080). If you don’t expose it to the host machine, it will still be reachable from other services in the same stack of network using the service name or host name.,If you look at https://hub.docker.com/_/mariadb, they connect adminer to a mariadb without any other configuration, since adminer is looking for the exposed db-port on all found containers in the stack.,I can create the container with docker-compose and also access the setup page from Nextcloud, but I’m not able to connect to my existing database which I created with VESTAcp.,I was able to solve this same issue simply by adding docker backend exe to windows firewall (Linux would be similar). https://arnav.jain.se/2019/allow-docker-through-windows-firewall/ You probably need to add port to your DB service as well. I use python and Jupyter notebook to connect to MariaDB, but any compatible tool should work. Hope that helps. I hope to post a note book on the subject soon.
Thanks for helping!
version: '3' volumes: # Macht Verzeichnis vom Host für Container verfügbar nextcloud: database: services: database: image: mariadb restart: always container_name: mariadb_container volumes: -/var/lib / mysql /: /var/lib / mysql / app: image: nextcloud: fpm - alpine restart: always volumes: -nextcloud: /var/www / html container_name: app_container links: -database environment: -MYSQL_ROOT_PASSWORD = testrootpasswort - MYSQL_PASSWORD = testpasswort - MYSQL_DATABASE = admin_nextcloud - MYSQL_USER = admin_nextcloud - MYSQL_HOST = localhost depends_on: -database web: build: . / web container_name: web_container restart: always ports: -8080: 80 volumes: -nextcloud: /var/www / html: ro depends_on: -app
2) Use a user-defined network (Best practice and recommended option). MySQL client-server example:,1) Link them together using --link. MySQL client-server example:
# First check remote access $ telnet[MYSQL_REMOTE_HOST][MYSQL_REMOTE_PORT] # Finally Run the container $ docker run - it mysql - h[MYSQL_REMOTE_HOST] - P[MYSQL_REMOTE_PORT] - u[MYSQL_REMOTE_USER]--password = [MYSQL_REMOTE_PASSWORD][MYSQL_REMOTE_DATABASE]
docker container run - d - p 3306: 3306--name mysql--env MYSQL_ROOT_PASSWORD = 123456 mysql docker container exec - it mysql bash
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2 “No such file or directory”),I found this by searching, check if it helps, Connecting MariaDB docker instance from MySQL workbench,How can i access mysql/mariadb in docker installatiom production mode,Once that is done, you can access mariadb on docker host on port 3306
docker exec -it <mariadb-container-name> bash
Then enter into Mariadb shell using root password
mysql - uroot - p
Start the Bitnami Ghost Docker container using the same configuration.,Confirm that you can connect to this database locally. I used the mysql-client to confirm this., Confirm that you can connect to this database locally. I used the mysql-client to confirm this. , The text was updated successfully, but these errors were encountered:
mysql\ - h $MARIADB_HOST\ - u $GHOST_DATABASE_USER\ --password = $GHOST_DATABASE_PASSWORD\ - D $GHOST_DATABASE_NAME\ - P $MARIADB_PORT_NUMBER
VPS server has mysql container runig (I dont expose 3306 port to the host). How can I can connect to that dockerized mysql server from my laptop without mounting mysql port to the host?,And then I've tried joining mysql container to it:,Reasoning: Why I want it this way? Because I dont want to make it (mysql server) visible to entire internet and thus attackers, but at same time i want easy access to mysql data from my laptop.,But I only get an error: root@vps:~$ sudo docker network connect infranet2mysql-server Error response from daemon: failed to create the macvlan port: invalid argument
What you can do is you can expose your port (3306) only on the internal ip, accessible via wireguard, such as the tunnel ip (as opposed to exposing it on all ips (0.0.0.0/0), as it happens by default). Given your tunnel ip is 192.168.0.1, this is how you would do it:
docker run--name mysql - server\ - p 192.168 .0 .1: 3306: 3306\ - e MYSQL_ROOT_PASSWORD = my - secret - pw\ - d mysql
Other "connecting-docker" queries related to "Connecting a Docker container to a remote MySQL Database"
- React Redux How to pass state from one container to another
- React not reading docker-compose environment variable
- Why ReactJS Dockerfile has two COPY commands?
- Standard_init_linux.go:219: exec user process caused: no such file or directory - docker problem
- Docker-compose, failed to solve: rpc error: code = Unknown desc = failed to compute cache key: “/app/package.json” not found: not found
- How can I use Material UI media queries inside fixed-width container?
- Table in react bootstrap. How can i make it fit inside a container?
- Why isn't container filling the whole screen?
- Tooltip gets cut off when a table container has overflow-x auto
- Is there any way to know the useParams from the top container?
- Uncaught (in promise) Error: InvalidStateError: While connecting my React client to Spring websocket server
- TZ variable passed to jest not taking effect with Jenkins docker slaves
- Grid of responsive squares with independently moving containers horizontally
- Keep scrolling outside when the content of scrollable container is over unless
- Deploy React Frontend, FastApi Backend with Docker-Compose on Heroku
- Uncaught Error: Target container is not a DOM element. React - Karma - Karma-webpack
- React - Uncaught Error: Target container is not a DOM element
- Importing a component from containers (From outside of the scope)
- How to move the icon in this flex container to the left?
- Uncaught Error: Target container is not a DOM element
- Can't run react app with docker container
- Connecting Redux Stores using Redux Toolkit
- React-Native another VirtualizedList-backed container
- Pass search value from one component to another container and use it in React
- Docker/Symfony/Reactjs/Keycloak : How to make an HTTP request from a container to another with separated docker-compose files?
- Why is my cron task working in command line, but not in PLESK?
- How to extract specific variables from a string?
- Apache fails to restart after PHP installation
- PHP ftp_put() - "Cannot STOR."
- Symfony2 - Logging not working on Production
- Load data infile gives me an access denied permissions error. How else can I import a text file into my table in my database?
- Insert a space between 2 echo
- How to pass many (over 100) variables into PHP
- PDO parameters not working at all
- Symfony 4 - Functional Test - Client not following redirects though followRedirects is true
- Why with resource is not executing in Laravel
- Highchart render in pdf generated using PHP mPdf
- How to set form field name in Symfony 2?
- Reading/submitting a form with variable-length sets of fields, read as an array server-side
- Yii2 how to use pjax when hyperlink is not in pjax
- How to structure a MySQL Database with 50 variables per user? [duplicate]
- Subtract from character class
- How can I place an arrayOfString datatype inside a php associative array
- Display custom checkout address field 2 label in Woocommerce
- Regular expression to split by space but ignore double-quotes string