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
Related
I am trying to deploy below stack in Portainer.io.
version: '3'
services:
app:
image: 'jc21/nginx-proxy-manager:latest'
restart: unless-stopped
ports:
- "80:80"
- "81:81"
- "443:443"
environment:
DB_MYSQL_HOST: "db"
DB_MYSQL_PORT: 3306
DB_MYSQL_USER: "admin"
DB_MYSQL_PASSWORD: "adminpwd"
DB_MYSQL_NAME: "nginx"
volumes:
- '/mnt/nginx/data:/data'
- '/mnt/nginx/letsencrypt:/etc/letsencrypt'
db:
image: 'jc21/mariadb-aria:latest'
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: 'adminpwd'
MYSQL_DATABASE: 'nginx'
MYSQL_USER: 'admin'
MYSQL_PASSWORD: 'adminpwd'
volumes:
- '/mnt/nginx/data/mysql:/var/lib/mysql'
Issue:
But I am getting this below error,
Deployment error
failed to deploy a stack: services.app.environment.volumes must be a string, number, boolean or null
Question:
I tried to change the format of volumes to different things but with no luck. What is wrong with this compose?
Volumes are at the environment variables indentation level, and it is of type list. So you need to indent the app volume as in db service and it should work.
version: '3'
services:
app:
image: 'jc21/nginx-proxy-manager:latest'
restart: unless-stopped
ports:
- "80:80"
- "81:81"
- "443:443"
environment:
DB_MYSQL_HOST: "db"
DB_MYSQL_PORT: 3306
DB_MYSQL_USER: "admin"
DB_MYSQL_PASSWORD: "adminpwd"
DB_MYSQL_NAME: "nginx"
volumes:
- '/mnt/nginx/data:/data'
- '/mnt/nginx/letsencrypt:/etc/letsencrypt'
db:
image: 'jc21/mariadb-aria:latest'
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: 'adminpwd'
MYSQL_DATABASE: 'nginx'
MYSQL_USER: 'admin'
MYSQL_PASSWORD: 'adminpwd'
volumes:
- '/mnt/nginx/data/mysql:/var/lib/mysql'
So I have two different applications one wordpress and other is api. And both running on docker containers and have their own configurations. This is their docker-compose settings:
version: "3.8"
services:
app:
container_name: ${APP_NAME}_app
build:
context: .
dockerfile: ./.docker/php/Dockerfile
expose:
- 9000
volumes:
- .:/usr/src/app
- ./public:/usr/src/app/public
depends_on:
- db
networks:
- app_network
nginx:
container_name: ${APP_NAME}_nginx
build:
context: .
dockerfile: ./.docker/nginx/Dockerfile
volumes:
- ./public:/usr/src/app/public
ports:
- "8081:8081"
expose:
- 8081
environment:
NGINX_FPM_HOST: app
NGINX_ROOT: /usr/src/app/public
depends_on:
- app
networks:
- app_network
db:
container_name: ${APP_NAME}_db
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
ports:
- "3307:3306"
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
networks:
- app_network
networks:
app_network:
driver: bridge
volumes:
db_data:
driver: local
And this is my wordpress configuration:
version: '3.8'
services:
mysql:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=somewordpress
- MYSQL_DATABASE=wordpress
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=wordpress
expose:
- 3306
- 33060
healthcheck:
test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD
interval: 1s
timeout: 3s
retries: 30
networks:
- app_network
wordpress:
build:
context: .
dockerfile: Dockerfile
depends_on:
mysql:
condition: service_healthy
volumes:
- .:/var/www/html/wp-content/plugins/name
ports:
- "80:80"
restart: always
environment:
- WORDPRESS_URL=http://localhost
- WORDPRESS_DB_HOST=mysql
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpress
- WORDPRESS_DB_NAME=wordpress
networks:
- app_network
networks:
app_network:
driver: bridge
And when I try to make request to api to this URL http://localhost:8081 well nothing happens. Locally works everything fine but on docker it doesn't.
Would appreciate some help how to make this work :)
If you have a docker container and you do http://localhost:8081, you wont go to your host pc, but to the container itself.
In docker-compose you need to replace localhost with the service name:
For example if you want to access 8081 of the nginx, you need to connect to http://nginx:8081
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
I am trying to deploy multiple apps on my docker host and have traefik route traffic based on hostnames to the different apps
I am using docker-compose for all my docker containers
Here is my traeffik.yaml file
version: '3.5'
services:
traefik:
image: traefik
container_name: traefik
command: --api --docker
networks:
- traefik_network
ports:
- "80:80"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
traefik_network:
name: traefik_network
here is my wpapp1.yaml file
version: '3.5'
services:
mysql:
image: mysql:5.7
volumes:
- wpapp1_mysql:/var/lib/mysql
restart: always
container_name: wpapp1_mysql
networks:
- traefik_network
environment:
MYSQL_ROOT_PASSWORD: wpapp1
MYSQL_DATABASE: wpapp1
MYSQL_USER: wpapp1
MYSQL_PASSWORD: wpapp1
wordpress:
depends_on:
- mysql
image: wordpress:latest
volumes:
- wpapp1_wordpress:/var/www/html
restart: always
container_name: wpapp1_wordpress
networks:
- traefik_network
labels:
- "traefik.frontend.rule=Host:wpapp1.example.com"
- "traefik.port=80"
- "traefik.docker.network=traefik_network"
environment:
WORDPRESS_DB_HOST: mysql:3306
WORDPRESS_DB_USER: wpapp1
WORDPRESS_DB_PASSWORD: wpapp1
volumes:
wpapp1_mysql:
name: wpapp1_mysql
wpapp1_wordpress:
name: wpapp1_wordpress
networks:
traefik_network:
external:
name: traefik_network
and here is my wpapp2.yaml file
version: '3.5'
services:
mysql:
image: mysql:5.7
volumes:
- wpapp2_mysql:/var/lib/mysql
restart: always
container_name: wpapp2_mysql
networks:
- traefik_network
environment:
MYSQL_ROOT_PASSWORD: wpapp2
MYSQL_DATABASE: wpapp2
MYSQL_USER: wpapp2
MYSQL_PASSWORD: wpapp2
wordpress:
depends_on:
- mysql
image: wordpress:latest
volumes:
- wpapp2_wordpress:/var/www/html
restart: always
container_name: wpapp2_wordpress
networks:
- traefik_network
labels:
- "traefik.frontend.rule=Host:wpapp2.example.com"
- "traefik.port=80"
- "traefik.docker.network=traefik_network"
environment:
WORDPRESS_DB_HOST: mysql:3306
WORDPRESS_DB_USER: wpapp2
WORDPRESS_DB_PASSWORD: wpapp2
volumes:
wpapp2_mysql:
name: wpapp2_mysql
wpapp2_wordpress:
name: wpapp2_wordpress
networks:
traefik_network:
external:
name: traefik_network
So now i expect traefik to route based on the hostnames wpapp1.example.com and wpapp2.example.com BUT traefik is loadbalancing traffic!!!
So when i go to http:/wpapp1.example.com, traefik is loadbalancing it between the two apps and same for the other hostnames. Now sure what is going on here since i specifically add the traefik.frontend.rule
I mean how in the hell is that happening?
I have spent hours to figure what is going on and before i go insane i decided to some here to get some help on what is going on here.
Put your database on a different network. Otherwise WordPress will RR load balance to the two mysql instances in the same docker network (that's the expected behavior when you have two containers with the same alias on the same network). You can do that with the default network:
version: '3.5'
services:
mysql:
image: mysql:5.7
volumes:
- mysql:/var/lib/mysql
restart: unless-stopped
networks:
- db
environment:
MYSQL_ROOT_PASSWORD: wpapp
MYSQL_DATABASE: wpapp
MYSQL_USER: wpapp
MYSQL_PASSWORD: wpapp
wordpress:
depends_on:
- mysql
image: wordpress:latest
volumes:
- wordpress:/var/www/html
restart: unless-stopped
networks:
- traefik
- db
labels:
- "traefik.frontend.rule=Host:wpapp1.example.com"
- "traefik.port=80"
- "traefik.docker.network=traefik_network"
environment:
WORDPRESS_DB_HOST: mysql:3306
WORDPRESS_DB_USER: wpapp
WORDPRESS_DB_PASSWORD: wpapp
volumes:
mysql:
wordpress:
networks:
db:
traefik:
external:
name: traefik_network
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