docker-compose cannot connect to mysql - docker

After hours of trying different things I find googling, still can't connect to MySQL.
This is my docker-compose.yaml
version: '3.5'
services:
apache:
build: .
container_name: apache-dot
restart: unless-stopped
volumes:
- ./www-data:/var/www
depends_on:
- mysql
ports:
- 80:80
mysql:
image: mysql:5.7
container_name: mysql-dot
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: xxxxxxxx
MYSQL_DATABASE: xxxxxxx
volumes:
- mysql-data:/var/lib/mysql
- ./mysql-dump:/docker-entrypoint-initdb.d
ports:
- 3306:3306
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin-dot
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: xxxxxxx
depends_on:
- mysql
ports:
- 8000:80
networks:
default:
volumes:
mysql-data:
driver: local
Docker compose builds correctly no with no errors.
docker logs and docker inspect doesn't reveal anything wrong.
docker network inspect looks good also.
Any help will be much appreciated.
Thank you.
SOLVED
I've had to add to the PHPMyAdmin service PMA_HOST: mysql.
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin-dot
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: xxxxxxx
PMA_HOST: mysql <====
depends_on:
- mysql
ports:
- 8000:80

Related

Docker image names are changed to sha256 after subsequent runs

I am using Docker 20.10.7 on Mac OS and docker-compose to run multiple docker containers.
When I start it for the first time, all the docker images are properly labeled and appear as the following.
However, after subsequent runs (docker-compose up, docker-compose down), suddenly all the image names are changed to sha256 and start to look like this
Please advise how to avoid this behavior. Thank you.
UPDATE #1
This is the docker-compose file I use to start containers.
Initially the old displayed with properly labeled image names.
However, not even if I run a docker system prune command it continues to label them as sha256:...
version: '3.8'
services:
influxdb:
image: influxdb:1.8
container_name: influxdb
ports:
- "8083:8083"
- "8086:8086"
- "8090:8090"
- "2003:2003"
env_file:
- 'env.influxdb.properties'
volumes:
- /Users/user1/Docker/influxdb/data:/var/lib/influxdb
restart: unless-stopped
telegraf:
image: telegraf:latest
container_name: telegraf
links:
- db
volumes:
- ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
- /var/run/docker.sock:/var/run/docker.sock
restart: unless-stopped
grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- "3000:3000"
env_file:
- 'env.grafana.properties'
links:
- influxdb
volumes:
- /Users/user1/Docker/grafana/data:/var/lib/grafana
restart: unless-stopped
db:
image: mysql
container_name: db-container
command: --default-authentication-plugin=mysql_native_password
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: P#ssw0rd
MYSQL_USER: root
MYSQL_PASSWORD: P#ssw0rd
MYSQL_DATABASE: db1
volumes:
- /Users/user1/Docker/mysql/data:/var/lib/mysql
- "../sql/schema.sql:/docker-entrypoint-initdb.d/1.sql"
healthcheck:
test: "/usr/bin/mysql --user=root --password=P#ssw0rd --execute \"SHOW DATABASES;\""
interval: 2s
timeout: 20s
retries: 10
restart: always
adminer:
image: adminer
container_name: adminer
restart: always
ports:
- 8081:8080
redis:
image: bitnami/redis
container_name: redis
environment:
- ALLOW_EMPTY_PASSWORD=yes
#- REDIS_DISABLE_COMMANDS=FLUSHDB,FLUSHALL
ports:
- '6379:6379'
volumes:
- '/Users/user1/Docker/redis/data:/bitnami/redis/data'
- ./redis.conf:/opt/bitnami/redis/mounted-etc/redis.conf

docker: Why do I access to phpmyadmin?

and excuse me for my English.
I'm using docker in wsl 2 and I have a docker application with three images: laravel, phpmyadmin and mysql
my problem is what I can not access to phpmyadmin.¿can I help me please?
Attached image of the docker application running.
Whe I tye to access to phpmyadmin, appearc not found page.
docker-compose.yml
version: '3.8'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.0/app
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
mysql:
image: 'mysql:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}' #empty(niether)
MYSQL_DATABASE: '${DB_DATABASE}' #fastfood
# MYSQL_USER: '${DB_USERNAME}' #root
MYSQL_PASSWORD: '${DB_PASSWORD}' #empty
MYSQL_HOST: '${DB_HOST}' #localhost
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
phpmyadmin:
image: 'phpmyadmin'
container_name: pma
environment:
PMA_HOST: '${DB_HOST}' #localhost
PMA_PASSWORD: '${DB_PASSWORD}' #empty(niether)
PMA_ARBITRARY: 1
restart: always
ports:
- 8081:80
depends_on:
- mysql
networks:
- sail
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
information
windows 10 19052.1052
docker 3.5.1
Use http://localhost:8081/ instead.
/phpmyadmin is just a route that set for the server software like wamp for you to access phpmyadmin easily.
Since you have defined in your docker-compose.yml
phpmyadmin:
image: 'phpmyadmin'
...
ports:
- 8081:80
...
which is port 8081

Cannot access phpMyAdmin Web on Docker Dekstop WSL2

I create Docker container for MariaDB database and phpMyAdmin.
When i run the container use Docker Compose i cannot access the phpMyAdmin web on http://localhost:8080
Here is my docker-compose.yml
version: '3.8'
services:
database:
container_name: database
image: mariadb:10.5.8-focal
restart: always
ports:
- 3307:3306
environment:
MYSQL_ROOT_PASSWORD: secret
volumes:
- ./data:/var/lib/mysql
- ./entrypoint:/docker-entrypoint-initdb.d
networks:
- db-network
phpmyadmin:
container_name: phpmyadmin
image: phpmyadmin:5.0.4-fpm-alpine
restart: always
ports:
- 8080:80
environment:
PMA_HOST: database
PMA_USER: root
PMA_PASSWORD: secret
depends_on:
- database
networks:
- db-network
networks:
db-network:
name: db-network

Cannot connect to second docker container - port error

I have two directories each running an identical docker build except for the allocated ports. I cannot connect to one of the containers in my localhost.
After running the docker ps command I see that 80/tcp being prepended to my second recipe-blog container. Below is my yml file, its nothing crazy, just setting up a database running php my admin and have it connect to a WordPress install. I also attached an image of the docker ps command.
services:
# Database
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
networks:
- wpsite
# phpmyadmin
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '9090:90'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
networks:
- wpsite
# Wordpress
wordpress:
depends_on:
- db
image: wordpress:5.3.0
ports:
- '9000:90'
restart: always
working_dir: /var/www/html
volumes:
- ./wp-content:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
networks:
- wpsite
networks:
wpsite:
volumes:
db_data: {}
wp-content:
Once again - finalsandbox_ I can connect to fine, I cannot connect to recipe-blog_. The only difference between the two yml files is that for the recipe-blog_ I changed the ports to be 9090:90 instead of 8080:80 and 9000:90 instead of 8000:80.
Thanks in advance.
It works for me, example
version: "3"
services:
# Database
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
networks:
- wpsite
# phpmyadmin
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '9090:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: wordpress
networks:
- wpsite
# Wordpress
wordpress:
depends_on:
- db
image: wordpress:5.3.0
ports:
- '9000:80'
restart: always
working_dir: /var/www/html
volumes:
- ./wp-content:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
networks:
- wpsite
networks:
wpsite:
volumes:
db_data: {}
wp-content:
Change all the ports assigned by 90 to 80.
docker-compose up -d
with your we-browser favorite, connect to http://127.0.0.1:9000 and http://127.0.0.1:9090

How to connect two services in the same stack network?

I have docker-compose.yaml file like:
version: '3.7'
services:
passbolt:
image: passbolt/passbolt
hostname: passbolt
container_name: passbolt
ports:
- 80:80
- 443:443
environment:
DATASOURCES_DEFAULT_HOST: mariadb
DATASOURCES_DEFAULT_USERNAME: passbolt
DATASOURCES_DEFAULT_PASSWORD: passbolt
DATASOURCES_DEFAULT_DATABASE: passbolt
APP_FULL_BASE_URL: https://my.url/
networks:
- passbolt_network
depends_on:
- mariadb
mariadb:
image: mariadb
hostname: mariadb
container_name: mariadb
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: passbolt
MYSQL_USER: passbolt
MYSQL_PASSWORD: passbolt
networks:
- passbolt_network
networks:
passbolt_network:
driver: overlay
I'm runnig stack by docker stack deploy -c docker-compose.yaml test
And passbolt service is exited because of Exception: There was a problem connecting to the database: SQLSTATE[HY000] [2002] Connection refused in (...)
You can also use network aliases :
version: '3.7'
services:
passbolt:
image: passbolt/passbolt
hostname: passbolt
container_name: passbolt
ports:
- 80:80
- 443:443
environment:
DATASOURCES_DEFAULT_HOST: alias_to_mariadb
DATASOURCES_DEFAULT_USERNAME: passbolt
DATASOURCES_DEFAULT_PASSWORD: passbolt
DATASOURCES_DEFAULT_DATABASE: passbolt
APP_FULL_BASE_URL: https://my.url/
networks:
- passbolt_network
depends_on:
- mariadb
mariadb:
image: mariadb
hostname: mariadb
container_name: mariadb
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: passbolt
MYSQL_USER: passbolt
MYSQL_PASSWORD: passbolt
networks:
passbolt_network:
aliases:
- "alias_to_mariadb"
networks:
passbolt_network:
driver: overlay

Resources