Connecting grafana and prometheus data from Docker [duplicate] - docker

I'm trying to run docker-compose.yml from here: https://github.com/Project-Books/book-project#running-the-app.
I tried to run a docker-compose file in Intellij IDEA Community Edition - using Docker plugin 202.7319.5
Here's the docker-compose.yaml file used: https://github.com/Project-Books/book-project/blob/master/docker-compose.yml
Here's the details about Docker Desktop installed:
OS: Windows
Version: 2.3.0.4(46911)
Channel: Stable
Engine: 19.03.12
Compose: 1.26.2
Output I'm getting in the console:
ERROR: for book-project_mysql_1 Cannot start service mysql: Ports are not available: listen tcp 0.0.0.0:3306: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
ERROR: for mysql Cannot start service mysql: Ports are not available: listen tcp 0.0.0.0:3306: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
Encountered errors while bringing up the project.

The port 3306 is already in use by other application. You can deploy MySQL to another port.
example docker-compose:
version: '3'
services:
mysql:
image: mysql:latest
hostname: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: bookproject
MYSQL_USER: dbuser
MYSQL_PASSWORD: dbpassword
ports:
- "3307:3306"
volumes:
- db_data:/var/lib/mysql
- ./src/main/resources/db/init.sql:/data/application/init.sql
command: --init-file /data/application/init.sql
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
links:
- mysql:db
ports:
- "8081:80"
bookapp:
build: ./
restart: on-failure
ports:
- "8080:8080"
environment:
- WAIT_HOSTS=mysql:3307
- WAIT_HOSTS_TIMEOUT=300
- WAIT_SLEEP_INTERVAL=30
- WAIT_HOST_CONNECT_TIMEOUT=30
#- DEFAULT_PATH=<Target path in windows>
depends_on:
- mysql
- phpmyadmin
volumes:
db_data:

I solved the problem by ending the "mysqld.exe" process in the task manager. Because this process has occupied port 3306.
First i had to find out which programme was using the port. The windows integrated gui of the resource monitor helped me here.
This Post helped me

"Ports are not available: listen tcp 0.0.0.0:3306"
Port 3306 is already in use.
In docker-compose file:
ports:
- "3306:3306" # Map TCP port 3306 in the container to port 3306 on the Docker host.
Try to change mapping port on host to another port (ex: 3366):
version: '3'
services:
mysql:
image: mysql:latest
hostname: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: bookproject
MYSQL_USER: dbuser
MYSQL_PASSWORD: dbpassword
ports:
- "3366:3306"

Related

Docker-Compose: Only one usage of each socket address (protocol/network address/port) is normally permitted

I'm trying to run docker-compose.yml from here: https://github.com/Project-Books/book-project#running-the-app.
I tried to run a docker-compose file in Intellij IDEA Community Edition - using Docker plugin 202.7319.5
Here's the docker-compose.yaml file used: https://github.com/Project-Books/book-project/blob/master/docker-compose.yml
Here's the details about Docker Desktop installed:
OS: Windows
Version: 2.3.0.4(46911)
Channel: Stable
Engine: 19.03.12
Compose: 1.26.2
Output I'm getting in the console:
ERROR: for book-project_mysql_1 Cannot start service mysql: Ports are not available: listen tcp 0.0.0.0:3306: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
ERROR: for mysql Cannot start service mysql: Ports are not available: listen tcp 0.0.0.0:3306: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
Encountered errors while bringing up the project.
The port 3306 is already in use by other application. You can deploy MySQL to another port.
example docker-compose:
version: '3'
services:
mysql:
image: mysql:latest
hostname: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: bookproject
MYSQL_USER: dbuser
MYSQL_PASSWORD: dbpassword
ports:
- "3307:3306"
volumes:
- db_data:/var/lib/mysql
- ./src/main/resources/db/init.sql:/data/application/init.sql
command: --init-file /data/application/init.sql
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
links:
- mysql:db
ports:
- "8081:80"
bookapp:
build: ./
restart: on-failure
ports:
- "8080:8080"
environment:
- WAIT_HOSTS=mysql:3307
- WAIT_HOSTS_TIMEOUT=300
- WAIT_SLEEP_INTERVAL=30
- WAIT_HOST_CONNECT_TIMEOUT=30
#- DEFAULT_PATH=<Target path in windows>
depends_on:
- mysql
- phpmyadmin
volumes:
db_data:
I solved the problem by ending the "mysqld.exe" process in the task manager. Because this process has occupied port 3306.
First i had to find out which programme was using the port. The windows integrated gui of the resource monitor helped me here.
This Post helped me
"Ports are not available: listen tcp 0.0.0.0:3306"
Port 3306 is already in use.
In docker-compose file:
ports:
- "3306:3306" # Map TCP port 3306 in the container to port 3306 on the Docker host.
Try to change mapping port on host to another port (ex: 3366):
version: '3'
services:
mysql:
image: mysql:latest
hostname: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: bookproject
MYSQL_USER: dbuser
MYSQL_PASSWORD: dbpassword
ports:
- "3366:3306"

Cannot connect with docker MySQL server container with the host name specified in docker-compose file

When I set hostname as localhost in MySQL Work Bench, It works. But when I use the hostname as msqldb it doesn't work and show that hostname msqldb cannot be resolved. What can be the issue?
Below is the docker-compose.yml
version: "3"
services:
msqldb:
image: mysql:8.0.20
environment:
MYSQL_ROOT_PASSWORD: psd
MYSQL_PASSWORD: psd
MYSQL_DATABASE: restaurantratingsystem
ports:
- "3315:3306"
dj:
container_name: dj
build: django
command: python manage.py runserver 0.0.0.0:80
volumes:
- ./django:/code
ports:
- "80:80"
depends_on:
- msqldb

Cannot log in to the MySQL server through browser

Each time when I try to access the phpmyadmin from browser I receive this error:
"Cannot log in to the MySQL server"
I tried to change networks, restart docker.
version: '3'
services:
web:
image: nginx:alpine
ports:
- 80:80
volumes:
- ./public_html:/public_html
- ./conf.d:/etc/nginx/conf.d
networks:
- nginxphp
php:
image: php:7.1.11-fpm-alpine
volumes:
- ./public_html:/public_html
expose:
- 9000
networks:
- nginxphp
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- "3306:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: root
MYSQL_PASSWORD: root
depends_on:
- db
ports:
- "8080:80"
networks:
nginxphp:
Cannot log in to the MySQL server
mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client
Disclaimer: I'm not a Docker user!
Your didn't mention if you're using the browser on the same computer as the sever or remotely. You'll need access to the mysql server (mysqld) through a terminal (command prompt). If this is a new install, it must be on the computer that is running mysql server.
In the Docker mysql page:
"The default configuration for MySQL can be found in /etc/mysql/my.cnf, which may include additional directories such as /etc/mysql/conf.d or /etc/mysql/mysql.conf.d."
Try looking in the /etc/mysql/my.cnf file on the server you're trying access. first. You're looking for:
bind-address = x.x.x.x
This is the address that the mysql server will talk to ("bound to"). Its typically "localhost" or "127.0.0.1".
To eliminate the error message like you see, I had to do two things:
1) change 'bind-address to 0.0.0.0'
this allows the server to connect to any computer. However, THIS IS A SECURITY RISK. Once you get it working, go read about bind addresses on the mysql website and set it appropriately.
2) Create an new account user#ipaddr where user is the new username and IPAddress is the ip4 address of the computer your trying to connect from. i.e.:
CREATE USER 'user'#'192.168.1.68' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'user'#'192.168.1.68';
Now try accessing mysql through the terminal program using the new username on the computer with the ip you entered above by typing:
mysql -uuser -ppassword -hx.x.x.x
Hopefully, this will help point you in the right direction. There's a ton of information about bind addresses and security on the web.
Because the phpmyadmin container has connected to the default host localhost. But your mysql server is located in other container (it means you cannot connect to mysql server by using localhost). So in the phpmyadmin service, you have to set PMA_HOST=db. See full env variables: https://hub.docker.com/r/phpmyadmin/phpmyadmin/
Full docker-compose.yml:
version: '3'
services:
web:
image: nginx:alpine
ports:
- 80:80
volumes:
- ./public_html:/public_html
- ./conf.d:/etc/nginx/conf.d
networks:
- nginxphp
php:
image: php:7.1.11-fpm-alpine
volumes:
- ./public_html:/public_html
expose:
- 9000
networks:
- nginxphp
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- "3306:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: root
MYSQL_PASSWORD: root
depends_on:
- db
ports:
- "8080:80"
networks:
nginxphp:
If you are using phpmyadmin with latest mysql version you will have some login issues:
Cannot log in to the MySQL server mysqli_real_connect():
The server requested authentication method unknown to the client [caching_sha2_password] mysqli_real_connect(): (HY000/2054):
The server requested authentication method unknown to the client
The solution is to downgrade to mysql 5.7 or another.
I tested with mysql 5.7 and it works for me.
If you want to can test with another versions and let the community know.
Below is the docker-compose file that builds and run Nginx + php 7.1 + mysql 5.7 +phpmyadmin
version: '3'
services:
web:
image: nginx:alpine
ports:
- 80:80
volumes:
- ./public_html:/public_html
- ./conf.d:/etc/nginx/conf.d
networks:
- nginxphp
php:
image: php:7.1.11-fpm-alpine
volumes:
- ./public_html:/public_html
expose:
- 9000
networks:
- nginxphp
db:
image: mysql:5.7
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db
environment:
PMA_HOST: db
PMA_PORT: 3306
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
depends_on:
- db
ports:
- "8080:80"
networks:
nginxphp:
Hope this will save some time to someone!

Docker - Container IP addresses mapping

In Docker, I have 3 containers which are node, mysql and redis. When I run sudo iptables -t nat -L -n I can see those containers are running on different IP addresses like below
However, the IP addresses order for the services and the IP addresses (on some machine it's 172.23.0.x, on some machine it's 172.21.0.x) might be different every time I do docker-compose up --build so if I want the app works, I gotta config IP addresses for each service manually. Is there any way I can automatically map a fixed IP address for each service in the docker-compose.yml file? Thanks. Here's my docker-compose.yml file:
version: "3"
services:
universe:
build: .
working_dir: /usr/src
volumes:
- .:/usr/src
- /usr/src/node_modules/
ports:
- "3000:3000"
- "8000:8000"
restart: always
# Redis Alpine
redis:
image: redis:alpine
ports:
- "127.0.0.1:6379:6379"
# MySQL 5.7
mysql:
build:
context: ./docker/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: database_name
MYSQL_USER: database_user
MYSQL_PASSWORD: database_password
volumes:
- /config/scripts:/docker-entrypoint-initdb.d
restart: always
ports:
- "127.0.0.1:3306:3306"
You can try this type of docker-compose.yml configuration with defining a network with bridge connection including subnet and gateway for that defined network.
version: "3"
services:
universe:
build: .
working_dir: /usr/src
volumes:
- .:/usr/src
- /usr/src/node_modules/
ports:
- "3000:3000"
- "8000:8000"
restart: always
networks:
vpcbr:
ipv4_address: 10.3.0.2
# Redis Alpine
redis:
image: redis:alpine
ports:
- "6379:6379"
networks:
vpcbr:
ipv4_address: 10.3.0.3
# MySQL 5.7
mysql:
build:
context: ./docker/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: database_name
MYSQL_USER: database_user
MYSQL_PASSWORD: database_password
volumes:
- /config/scripts:/docker-entrypoint-initdb.d
restart: always
ports:
- "3306:3306"
networks:
vpcbr:
ipv4_address: 10.3.0.4
networks:
vpcbr:
driver: bridge
ipam:
config:
- subnet: 10.3.0.0/16
gateway: 10.3.0.1
In your Docker Compose setup as you’ve shown it, to communicate between containers, you can use the names of the services (universe, redis, mysql) as ordinary host names and they’ll resolve to the internal IP address of the container, whatever it happens to be.
Note that if you’re using the ports: option to remap a published port, you still need to connect to the internal port (the one on the right side of the colon). For instance you’d connect to mysql:3306 even if you specified a different external port mapping or not port mapping at all.
This doesn’t work from outside of Docker space; there you connect to the host’s DNS name or IP address with the published ports:, and the fact of Docker is totally hidden from you.

Can't access Docker database using IP (only localhost)

I'm trying to setup Docker to allow connections from other devices on my network. Currently to access Docker I visit localhost on my computer. I'm trying to connect using my computer's local IP (192.168.0.140), which lets me see my files but not connect to my database.
I assume this is a problem with my configuration but I don't know enough about Docker to troubleshoot it.
version: '2'
services:
webserver:
build: ./docker/webserver
image: localdev
ports:
- '80:80'
- '443:443'
volumes:
- ./www:/var/www/html
links:
- db
db:
image: mysql:5.6
ports:
- 3306
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=secret
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
links:
- db
environment:
PMA_HOST: db
PMA_PORT: 3306
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: secret
ports:
- '8080:80'
Any help would be greatly appreciated.
Maybe you should try like this :
version: '2'
services:
webserver:
build: ./docker/webserver
image: localdev
ports:
- '0.0.0.0:80:80' # Map container port 80 on your "public" ip on port 80, it will be available on the network
- '0.0.0.0:443:443' # Same for port 443
volumes:
- ./www:/var/www/html
links:
- db
db:
image: mysql:5.6
# ports:
# - 3306 # You don't need to map port 3306 because mysql already expose this port for others containers, unless you wan't to access to your mysql directly
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=secret
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
#links:
# - db # Not necessary, with docker-compose v2 every containers are in the same network and see each other
environment:
PMA_HOST: db
PMA_PORT: 3306
MYSQL_USER: root
MYSQL_ROOT_PASS
WORD: secret
ports:
- 'localhost:8080:80' # to keep your phpmyadmin only available from localhost.
The reason you are able to connect to the other containers is because you have mapped the ports between the container and the host.
For the database you are using the short port syntax:
ports:
- 3306
This will choose a random port on the host. To be able to connect to the database, use the long form syntax:
ports:
- '3306:3306'
In that case, you will be able to connect to the database on localhost:3306

Resources