Banging my head at 2:30 a.m.
I have three Docker containers MariaDB, Nginx and PhpFpm.
MariaDB opens up 3306/tcp - no exposed port because all container share the same Docker Network.
Symfony starts up in PhpFpm and is exposed via Nginx on port 8081.
So myhost.com:8081 shows my Symfony application.
When I docker exec bash into my PhpFpm container and execute bin/console doctrine:schema:create schema is created, MariaDB has a new table.
Of course I clear the cache and warm it up for APP_ENV=prod
var/log and var/cache have set correct permissions.
No matter what I do, when using the PDO connection within my Symfony application's controller I get an
Connection refused error
visible in my prod.log within the container.
I tried .env with several options, most prominent are:
DATABASE_URL="mysql://user:pass#hostname:8084/db" (here I set -p 8084:3306 for MariaDB Container)
and
DATABASE_URL="mysql://user:pass#mariadbcontainername:3306/db" (here I did not expose any DB port as mentioned above)
Does anyone have an idea where to look and what to test?
I can even verify that my bin/console doctrine... commands are already getting a Connection Refused error when I change the DATABASE_URL to a nonsense value.
P.S.: Due to server restrictions I don't use docker-compose but simply docker run.
Related
I tried to install a MySQL cluster with the Docker image below.
mysql/mysql-cluster - Docker Image | Docker Hub
The Docker image is pulled and run successfully.
Despite that I could connect to the cluster in the terminal (as shown in the screen capture below), I don't know how to connect to it with MySQL Workbench or DBeaver.
In your docker run command, you can use -p 3306:3306 (or any available port). Then you can use <host>:<port> from Workbench or Dbeaver connection URL.
I assume that you already know how to add new DB connection to MySQL Workbench or DBeaver. The information that you want is the connection URL and the username/password of an authenticated user that you need to use to connect to your MySQL cluster.
For the connection URL: 192.168.0.10 (no port in your example)
You need to have your MySQL Workbench or DBeaver connect to the URL of the MySQL node, which is mysql1 node in your example. As shown in your screen capture, it is 192.168.0.10 without any explicit port. But if you have troubles with the URL, you can run docker ps to check what host and port that your mysql1 is running and exposed at.
For the username/password: root/tpffnrtm1 (the password is the value of MYSQL_ROOT_PASSWORD as shown in your docker run of MySQL node command)
I assume that you just want to connect the DB cluster by any means (root or non-root privileges is totally fine for you).
I am working on simple project with mysql + springboot using docker container and i am able to run in my local without any issue. I tried to bring the same containers to AWS ECS to standup but i am facing multiple problems. I did research multiple documents and blogs but could not get the correct content to make this works.
I used the below to stand up the mysql in my local with the container name of "mysqlcontainer"
docker run --restart always --name mysqlcontainer --net dev-network -v /Users/myuser/Develop/mysql_data/8.0:/var/lib/mysql -p 3306:3306 -d
-e MYSQL_ROOT_PASSWORD=password mysql:8.0
Once mysql stood up then i ran the below command to bring my springboot application. This is simple springboot service which has the CRUD operation with mysql.
docker run -d -p 8061:8061 --name user-mysqlapp --net dev-network
--link mysqlcontainer user-mysql
mysql container name is "mysqlcontainer" which runs on the network "dev-network" and i have used these container and network name in second docker command to stand up the springboot application as both container needs to talk each other within the same network.
here is the docker file for springboot application.
FROM openjdk:8-jdk-alpine
EXPOSE 8061 ARG
JAR_FILE=target/user-mysql.jar
ADD ${JAR_FILE} user-mysql.jar
ENTRYPOINT ["java","-jar","user-mysql.jar"]
Here is the datasource that is being used in application.yml within springboot application.
datasource:
url: jdbc:mysql://mysqlcontainer:3306/sample
username: dummy
password: password
driver-class-name: com.mysql.jdbc.Driver
after both containers are running, i was able to connect the mysql with mysqldeveloper and able to execute the below command.
CREATE USER 'dummy'#'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'dummy'#'%';
create database sample;
use sample;
I have no issue of executing this setup in my local and i did push the springboot application image to dockerhub to use in AWS ECS.
Problem statement:
If i run the mysql container alone in ECS, i am able to run it and able to connect using mysql developer from my local. but if i try to run springboot app image, its not properly linking with mysql container. I tried in FARGATE instance type with awsvpc network mode where i was unable to give link to mysql container. i did tried to create single taskdefinition where both containers were added and both of them were running successfully but in the spring boot log, it says unable to create the communication with mysql container.
Can someone please share some information to stand up this setup in aws ecs or share some link/tutorial/blog where i can see how this mysql + springboot app setup can stand up in aws ecs? if i am able to stand up these containers then i need to create/attach volume to the persisting the data in aws. Thanks in advance...
I am able to setup this spring boot + mysql setup successfully in ECS. Below are the steps were followed.
Create one task definition in which add mysql container first where
provide the necessary env variable to mysql container.
Add another spring boot container in which set the dependency order
container as mysql container with condition of "START".
Create new cluster
Create service on this cluster and then add this task definition on the service.
Since i used fargate type, we can't use link to refer the other container but instead i used 127.0.0.1 ip address in spring boot application yml data source url so that it will refer the local host within the same network. This solves the container linking issue and i am sure we would have some better option but for time being i am using this option.
datasource:
url: jdbc:mysql://127.0.0.1:3306/sample
I am trying to develop a micro service that gets information from a remote database but when I run the container it fails to make a connection to that database.
The container is running locally (I'm still developing it) and the database is hosted in AWS RDS Aurora MySQL.
The database is in use on multiple production websites using the same user I'm trying to use in the container. The user has full permission to the database and my local PHPMyAdmin connects to the database using that same user and I've had no trouble managing the db with it.
The problem is that the database connection in the container fails with an Access denied error.
The database user is setup as dbuser#% yet the error says:
Access denied for user 'dbuser'#'[my public ip]' (using password:
YES).
I attempted to add another account for dbuser#[my public ip] and gave it the same permissions as the wildcard host account and that makes no difference.
As another test I added a curl call inside the container to load an external page to make sure it can make external connections and that succeeds. It's just the db connection failure that makes no sense.
My dockerfile looks like this:
FROM php:7.2-apache
RUN apt-get update
RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN a2enmod rewrite
I'm hoping someone has come across this and/or knows what I'm missing here.
Thanks in advance!
Some more info:
I'm using Docker for Windows and docker-compose to run my container. My docker-compose.yml file looks like:
version: "3"
services:
web:
image: repository/container:latest
volumes:
- ./src:/var/www/html
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "80:80"
networks:
- inv
networks:
inv:
Starting the container with docker run --network host ... will make the container share the network stack of the host. That should solve the problem.
I ended up fixing this by copying the original connection code from my API and replacing the connection code in my container with it.
I commented out the broken code and compared the two but see no difference. No quote marks in the host string, no typos, nothing that makes sense.
The only difference is the way I'm setting the variables that build the host string. The values of those variables are the same so it really doesn't make sense.
Regardless, doing this fixed it.
I have a locally running MySQL server.. it's NOT within a container. My app is going to be hitting RDS so no sense in going that route. My app was able to hit RDS no problem, as a test. But obviously I want to hit something local for local development.
From my terminal I can do mysql --user=root --password=password mydb successfully.
And as I'm not getting a timeout error, from my container I can ping 127.0.0.1:3306 with no issue.
I also used console to see I am definitely passing the right info, after having updated the values from RDS to locally running MySQL.
Docker container has its own network IPs, including its own localhost. So you basically need to be sure of two things:
That your host MySQL is listening in all of its interfaces (bind-addres = 0.0.0.0 in my.cnf). Check with netstat -na|grep 3306.
Figure out the host ip that your container can reach. So check the IP of the container: docker inspect container-id, find the IP, and replace the last part with .1, that should be the IP of your host in the containers own network. I.e. 172.17.0.1 (it can be considered as fixed IP, for dev environment it's ok)
So most likely that this is what you need: 172.17.0.1:3306
I have running docker MySQL container on production server.
I need to connect to MySQL database from another server.
Container just have EXPOSE 3306, but no binded ports.
So, i understand that binding port to a running container is not possible.
I thinking about creating new "proxy" container, bind ports to listen outside and link it to existing MySQL container.
Will this work?
Sorry for my english
Just run your container with -P option or with -p <host_machine_port>:<container_port>
For MySQL it can be done with docker run -p 3306:3306 mysql
And you can connect to MySQL through yourmysqldomain.com:3306