I have next docker-compose.yml
version: '3'
services:
webserver:
build: './Docker/apache-php/'
depends_on:
- db
ports:
- "80:80"
volumes:
- ./:/var/www/html/
db:
image: mariadb:latest
environment:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_DATABASE: dmm
MYSQL_USER: dmm
MYSQL_PASSWORD: password
That works nice. I can connect to database from webserver using db:3306 adress.
But if I add any volume to db container like
version: '3'
services:
webserver:
build: './Docker/apache-php/'
depends_on:
- db
ports:
- "80:80"
volumes:
- ./:/var/www/html/
db:
image: mariadb:latest
environment:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_DATABASE: dmm
MYSQL_USER: dmm
MYSQL_PASSWORD: password
volumes:
- ./db/:/var/lib/mysql/
db:3306 refuses all conections
Whats wrong?
Related
compose.yml found on github to create a LAMP environment.
The script works fine, but I can't understand how as it doesn't state an image property for apache or mysql, please can you let me know how it knows what image to use.
version: "3"
services:
webserver:
build:
context: ./bin/${PHPVERSION}
container_name: "${COMPOSE_PROJECT_NAME}-${PHPVERSION}"
restart: "always"
ports:
- "${HOST_MACHINE_UNSECURE_HOST_PORT}:80"
- "${HOST_MACHINE_SECURE_HOST_PORT}:443"
links:
- database
volumes:
- ${DOCUMENT_ROOT-./www}:/var/www/html:rw
- ${PHP_INI-./config/php/php.ini}:/usr/local/etc/php/php.ini
- ${SSL_DIR-./config/ssl}:/etc/apache2/ssl/
- ${VHOSTS_DIR-./config/vhosts}:/etc/apache2/sites-enabled
- ${LOG_DIR-./logs/apache2}:/var/log/apache2
- ${XDEBUG_LOG_DIR-./logs/xdebug}:/var/log/xdebug
environment:
APACHE_DOCUMENT_ROOT: ${APACHE_DOCUMENT_ROOT-/var/www/html}
PMA_PORT: ${HOST_MACHINE_PMA_PORT}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
HOST_MACHINE_MYSQL_PORT: ${HOST_MACHINE_MYSQL_PORT}
XDEBUG_CONFIG: "client_host=host.docker.internal remote_port=${XDEBUG_PORT}"
extra_hosts:
- "host.docker.internal:host-gateway"
database:
build:
context: "./bin/${DATABASE}"
container_name: "${COMPOSE_PROJECT_NAME}-${DATABASE}"
restart: "always"
ports:
- "127.0.0.1:${HOST_MACHINE_MYSQL_PORT}:3306"
volumes:
- ${MYSQL_INITDB_DIR-./config/initdb}:/docker-entrypoint-initdb.d
- ${MYSQL_DATA_DIR-./data/mysql}:/var/lib/mysql
- ${MYSQL_LOG_DIR-./logs/mysql}:/var/log/mysql
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
phpmyadmin:
image: phpmyadmin
container_name: "${COMPOSE_PROJECT_NAME}-phpmyadmin"
links:
- database
environment:
PMA_HOST: database
PMA_PORT: 3306
PMA_USER: root
PMA_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
UPLOAD_LIMIT: ${UPLOAD_LIMIT}
MEMORY_LIMIT: ${MEMORY_LIMIT}
ports:
- "${HOST_MACHINE_PMA_PORT}:80"
- "${HOST_MACHINE_PMA_SECURE_PORT}:443"
volumes:
- /sessions
- ${PHP_INI-./config/php/php.ini}:/usr/local/etc/php/conf.d/php-phpmyadmin.ini
redis:
container_name: "${COMPOSE_PROJECT_NAME}-redis"
image: redis:latest
ports:
- "127.0.0.1:${HOST_MACHINE_REDIS_PORT}:6379"
Image is for predefined images that can be found on dockerhub.
The build property defines the location of images that you might've created or modified that are on your local computer that need to built.
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'
I want to persist the data (datatasets, graphs and dashboards) so that when the container is deleted they are not deleted and when I run it again they are present
My docker-compose:
version: '2.4'
services:
mariadb:
container_name: mariadb
image: mariadb
restart: always
volumes:
- ./mariadb-data:/var/lib/mysql
environment:
MYSQL_DATABASE: 'db_prueba'
MYSQL_USER: 'admin'
MYSQL_PASSWORD: 'admin'
MARIADB_ROOT_PASSWORD: 'admin'
ports:
- 2022:3306
supeset:
container_name: superset
build: .
restart: always
depends_on:
- mariadb
environment:
MAPBOX_API_KEY: 'pk.eyJ1IjoiamFta2lsbHM1IiwiYSI6ImNrd293aDJyZjA3MGQyd3AzdTJpeXp0dTAifQ.w96chqjB6Nv3PW6_lpQVHQ'
DATABASE_PORT: 2022
DATABASE_DIALECT: 'mysql'
MYSQL_DATABASE: 'db_prueba'
MYSQL_USER: 'root'
MYSQL_PASSWORD: 'admin'
MYSQL_RANDOM_ROOT_PASSWORD: yes
ports:
- 8000:8088
#volumes:
./superset-data:/app/pythonpath
No volumes are created locally and no data is stored in superset. I have looked in docker-hub and they do not specify the address of the volumes.
https://hub.docker.com/r/apache/superset/
I have updated my code but the data still does not persist. I currently have this docker-compose
version: '2.4'
services:
mariadb:
container_name: mariadb
image: mariadb
restart: always
volumes:
- ./mariadb-data:/var/lib/mysql
environment:
MYSQL_DATABASE: 'db_prueba'
MYSQL_USER: 'admin'
MYSQL_PASSWORD: 'admin'
MARIADB_ROOT_PASSWORD: 'admin'
ports:
- 2022:3306
supeset:
container_name: superset
build: .
restart: always
depends_on:
- mariadb
environment:
MAPBOX_API_KEY: 'pk.eyJ1IjoiamFta2lsbHM1IiwiYSI6ImNrd293aDJyZjA3MGQyd3AzdTJpeXp0dTAifQ.w96chqjB6Nv3PW6_lpQVHQ'
DATABASE_DB: 'superset'
DATABASE_HOST: 'mariadb'
DATABASE_PASSWORD: 'admin'
DATABASE_USER: 'admin'
DATABASE_PORT: 2022
DATABASE_DIALECT: 'mysql'
MYSQL_DATABASE: 'db_prueba'
MYSQL_USER: 'root'
MYSQL_PASSWORD: 'admin'
MYSQL_RANDOM_ROOT_PASSWORD: yes
Any ideas?
I have been trying to understand this process of having an docker-compse.yml file that I can re-use for many production with diffrent hosts, sql password and user and so on.
I've been trying out on this file fx.
services:
db_node_domain:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: PASSWORD
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: PASSWORD
container_name: wordpress_db
wordpress:
depends_on:
- db_node_domain
image: wordpress:latest
expose:
- 80:80
restart: always
environment:
VIRTUAL_HOST: sub.domain.example
WORDPRESS_DB_HOST: db_node_domain:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: $TEST
container_name: wordpress
volumes:
db_data:
networks:
default:
external:
name: nginx-proxy
And then I've tried to use varibales in gitlab to change the WORDPRESS_DB_PASSWORD in many ways. This is just one example of trying.
I also tried to use sed -i in .gitlab-ci.yml to change password but I wanted to know if someone could help me out on how to do this.
Thx
You just need to replace hardcoded creds with environment variables.
Then each stages will have creds/settings.
In Gitlab go your project, then Settings > "CI / CD" > Variables.
Then populate each ENV variable needed, hey will be present on each run
services:
db_node_domain:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
container_name: wordpress_db
wordpress:
depends_on:
- db_node_domain
image: wordpress:latest
expose:
- 80:80
restart: always
environment:
VIRTUAL_HOST: ${VIRTUAL_HOST}
WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST}
WORDPRESS_DB_USER: ${WORDPRESS_DB_USER}
WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD}
container_name: wordpress
volumes:
db_data:
networks:
default:
external:
name: nginx-proxy
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