I'm trying to use a docker-compose.yml for launching mariabd and phpmyadmin. When I edit something on phpmyadmin it kicks me out to login page.
db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: Pass123
restart: always
volumes:
- "./.data/db:/var/lib/mysql/:rw"
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db:mysql
ports:
- 8181:80
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: Pass123
PMA_HOST: mysql
I've tried with a volume container with busybox to keep data of mysql, changed mariabd for mysql image. But I don't get with the solution. What should I do to solve this?
Thanks in advance
The set of environmental variables supported by the phpmyadmin/phpmyadmin Docker image is different from that of the mariadb image. Try replacing the MYSQL_USERNAME and MYSQL_ROOT_PASSWORD variables of your phpmyadmin service with PMA_USER and PMA_PASSWORD, respectively.
I don't understand the meaning of the link
links:
- db:mysql
The configuration file of phpmyadmin/phpmyadmin (/www/config.inc.php) say by default the host name of database server if 'db' :
$hosts = array('db');
As you name the database server 'db' then link should be write likez this :
links:
- db
If your database name container is not 'db', you should add the environment variable PMA_HOST= (or PMA_HOSTS if multi db servers) with the right name
All over environment variables are useless (even in db config I think)
Related
I'm trying to run mysql under container with mysql parameters i defined on docker-compose.yml file. But i have an access denied when i run :
mysql -utest -ptest
I'm only able to connect with mysql -uroot -proot.
Help me please.
Thanks.
mysql:
container_name: mysql
image: mysql
restart: always
volumes:
- .docker/data/db:/var/lib/mysql
environment:
MYSQL_DATABASE: app
MYSQL_ROOT_PASSWORD: test
MYSQL_USER: test
MYSQL_PASSWORD: test
Try to launch with specified database name like this:
mysql -u test -p test app
Explanation:
MYSQL_USER, MYSQL_PASSWORD
These variables are optional, used in conjunction to create a new user and to set that user's password. This user will be granted superuser permissions (see above) for the database specified by the MYSQL_DATABASE variable. Both variables are required for a user to be created.
From MySQL docker hub page
Permissions are granted only for the database specified by environment variable. When you try to log into default database you have no permissions to it only for app database.
My complete docker-compose file.
version: '3.2'
services:
apache:
container_name: apache
build: .docker/apache/
restart: always
volumes:
- .:/var/www/html/app/
ports:
- 80:80
depends_on:
- php
- mysql
links:
- mysql:mysql
php:
container_name: php
build: .docker/php/
restart: always
volumes:
- .:/var/www/html/app/
working_dir: /var/www/html/app/
mysql:
container_name: mysql
image: mysql
restart: always
volumes:
- .docker/data/db:/var/lib/mysql
environment:
MYSQL_DATABASE: app
MYSQL_ROOT_PASSWORD: test
MYSQL_USER: test
MYSQL_PASSWORD: test
Maybe you could try attaching an interactive bash process to the already running container by following these steps:
Get your container id or name from running docker container ls in your terminal (I'm talking about the mysql container, which should have the mysql name according to your docker-compose.yml file)
Run docker exec -it mysql bash to associate an interactive bash process to the running container
Now, being inside of your container's filesystem, run mysql --user=test --password=test and you should be able to get on with your work
I'm pretty new to docker and I guess I have made a proper beginner mistake here but I really can't get my head around of what's wrong...
I have sucesfully created a docker container with a running Wordpress installation. The link to the DB does work there. I can also access phpmyadmin but I can't get in. The following errors appear:
Invalid hostname for server 1. Please review your configuration.
Connection for controluser as defined in your configuration failed.
This is my docker.yml
version: "2"
services:
my-wpdb:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: letmein
my-wp:
image: wordpress
volumes:
- ./:/var/www/html
ports:
- "8080:80"
links:
- my-wpdb:mysql
environment:
WORDPRESS_DB_PASSWORD: letmein
phpmyadmin:
image: corbinu/docker-phpmyadmin
links:
- my-wpdb:mysql
ports:
- 8181:80
environment:
MYSQL_USERNAME: letmein
MYSQL_ROOT_PASSWORD: letmein
I'm trying to log in with: root, letmein
Thank's! Any help appeciated!
Your phpmyadmin is probably trying to connect to mysql using a different hostname from what you expect. (localhost probably?)
In your specific case you need to set it to use my-wpdb, more specifically you want to set that $MYSQL_PORT_3306_TCP_ADDR to point to your database.
From the source code of that (deprecated) docker image is not quite clear, but I'm guessing you need to specify that with
phpmyadmin:
image: corbinu/docker-phpmyadmin
ports:
- 8181:80
environment:
MYSQL_USERNAME: letmein
MYSQL_ROOT_PASSWORD: letmein
MYSQL_PORT_3306_TCP_ADDR: my-wpdb
I have the following docker-compose.yml file:
version: '3'
services:
maria_service:
build: ./db_maria
restart: always
environment:
MYSQL_DATABASE: mariadb
MYSQL_USER: joel
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
volumes:
- ./db:/var/lib/mysql
drupal_service:
build: ./website
restart: always
ports:
- 8080:80
volumes:
- /var/www/html/modules
- /var/www/html/profiles
- /var/www/html/themes
# this takes advantage of the feature in Docker that a new anonymous
# volume (which is what we're creating here) will be initialized with the
# existing content of the image at the same location
- /var/www/html/sites
depends_on:
- maria_service
Here's my working directory:
Here's the drupal dockerfile where all I'm doing is to pull the drupal image:
Here's the mariadb dockerfile:
It automatically generate this "db" subfolder seen in the pic below:
My issue is everytime I enter mariadb on the drupal UI at localhost:8080, it throws this error below:
UPDATES:
Based on #Tarun Lalwani answer, my issue was that, in the Drupal UI, I would enter my username, password and db name but if you expand that Advanced Options in that Drupal screenshot, you'll see that the HOSTNAME was pointing to "localhost" when it should be pointing to the actual hostname of the mariadb database server which in DOCKER WORLD, the hostname name of a running container is ITS SERVICE NAME i.e "mariadb_service" as seen in the docker-compose.yml file - see screenshot. Hope I wasn't the only newbie that bumped into that and will help others, thanks Tarun Lalwani!!
You need to set the Host name also for the DB in Drupal. This db host will be maria_service as per the service name from your docker-compose.yml file. This needs to be done by expanding the Advanced options
Using Environment Variables
You could also try setting the environment variables for these settings
version: '3'
services:
maria_service:
build: ./db_maria
restart: always
environment:
MYSQL_DATABASE: mariadb
MYSQL_USER: joel
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
volumes:
- ./db:/var/lib/mysql
drupal_service:
build: ./website
restart: always
ports:
- 8080:80
volumes:
- /var/www/html/modules
- /var/www/html/profiles
- /var/www/html/themes
# this takes advantage of the feature in Docker that a new anonymous
# volume (which is what we're creating here) will be initialized with the
# existing content of the image at the same location
- /var/www/html/sites
depends_on:
- maria_service
environment:
DB_HOST: maria_service
DB_USER: joel
DB_PASSWORD: password
DB_NAME: mariadb
DB_DRIVER: mysql
My own_app requires a MySQL database. The problem is that the own_app container needs to ip of the MySQL database. My aim is to solve this issue by using docker-compose.yml.
Dockerfile
ENTRYPOINT ["docker-entrypoint.sh"]
docker-compose.yml
Based on the Wordpress example the docker-compose.yml has been slightly modified as follows:
version: '2'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
own_app:
depends_on:
- db
image: own_app:latest
ports:
- "8000:80"
restart: always
environment:
MYSQL_DB_HOST: db:3306
volumes:
db_data:
but it inserts db:3306
db.default.url="jdbc:mysql://db:3306/database_name"
instead of an IP address
Problem
The sed statement that resides in the docker-entrypoint.sh works well, i.e. it replaces localhost with the $MYSQL_DB_HOST environment variable. The problem is that docker-compose returns db:3306 instead of <ip>:3306
Question
Why is docker-compose not looking up the IP address?
Environment variables in docker-compose are just strings, it doesn't know if it's a hostname or any other text. The only parsing that's done is to expand variables in the ${varname} syntax.
For connecting containers together, you don't want IP addresses anyway, they can change. Use the DNS based discovery which will resolve "db" from the service name in any other containers that are on the same network.
Instead of below mysql container DB link, I want to link AWS Mysql RDS in docker yml file. Is it possible?
mysql_db:
image: mysql:5.6
container_name: shishir_db
environment:
MYSQL_ROOT_PASSWORD: "xxxxxxxx"
#MYSQL_USER: "shishir"
#MYSQL_DATABASE: "shishir1"
MYSQL_PASSWORD: "xxxxxxxx"
ports:
- "3306:3306"
There are a couple of ways that you can link to a AWS RDS MySQL instance from your docker-compose.yml.
The first, and perhaps simplest way is to set environment variables on the containers that need access to the RDS MySQL instance. So for example, you could update your OperationEngine service definition to look something like:
OperationEngine:
image: shishir/operationengine:${RELEASE_OTA_VERSION}
container_name: operation_engine
ports:
- "8080:8080"
environment:
- DOCKER_HOST_IP: ${DOCKER_HOST_IP}
- JAVA_OPTS: ${JAVA_OPTS}
- MYSQL_HOST: "your-mysql-cname.rds.amazon.com"
- MYSQL_USER: "username"
- MYSQL_PASSWORD: "password"
volumes:
- ${HOME}/operationengine/logs/:/usr/local/tomcat/logs/
You can then update the configuration in that service to read database connection details from the environment e.g ${MYSQL_HOST}.
The obvious downside to this approach is that you have connection details stored as plain text in your docker-compose.yml, which is not great, but may be acceptable depending on your requirements.
The 2nd approach (and the one I tend to favour) is to bind mount the database configuration into the running container.
Most applications support reading database connection details from a properties file. As an example: lets say that on start-up your application read from /config/database.properties and required the following properties to connect to the database:
config.db.host=your-mysql-cname.rds.amazon.com
config.db.user=foo
config.db.password=bar
I would setup my environment so that at runtime, I bind mount a properties file that provides all of the required values to the container:
OperationEngine:
volumes:
- /secure/config/database.properties:/config/database.properties
The /secure/config directory is part of the filesystem on your Docker host. How that directory gets created and populated is up-to-you. Typically I approach this by having my environment setup scripts make the directory and then clone a private Git repository into this directory which contains the correct configuration for that environment. Naturally only those with the required permission levels can view the Git repositories that contain sensitive configuration details i.e. for production system.
Hope that helps.
No, i have not created networking in my yml file. Below is the entirecontent of my yml file, so what changes would be required?
mysql_db:
image: mysql:5.6
container_name: shishir_db
environment:
MYSQL_ROOT_PASSWORD: "xxxxxxxx"
#MYSQL_USER: "shishir"
#MYSQL_DATABASE: "shishir1"
MYSQL_PASSWORD: "xxxxxxxx"
ports:
- "3306:3306"
zookeeper:
image: wurstmeister/zookeeper
container_name: zookeeper
ports:
- "2181:2181"
kafka:
image: shishir/kafkaengine:0.10
container_name: kafka
links:
- zookeeper
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: ${DOCKER_HOST_IP}
KAFKA_ZOOKEEPER_CONNECT: ${DOCKER_HOST_IP}:2181
KAFKA_ADVERTISED_PORT: 9092
KAFKA_CREATE_TOPICS: ${KAFKA_TOPICS}
KAFKA_ZOOKEEPER_SESSION_TIMEOUT_MS: 12000
KAFKA_ZOOKEEPER_CONNECTION_TIMEOUT_MS: 12000
flywaydb:
image: shishir/flywaydb
container_name: flywaydb
links:
- mysql_db
OperationEngine:
image: shishir/operationengine:${RELEASE_OTA_VERSION}
container_name: operation_engine
links:
- mysql_db
ports:
- "8080:8080"
environment:
DOCKER_HOST_IP: ${DOCKER_HOST_IP}
JAVA_OPTS: ${JAVA_OPTS}
volumes:
- ${HOME}/operationengine/logs/:/usr/local/tomcat/logs/