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.
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'
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 am creating containers for all my projects, mostly in Wordpress, and I was wondering if for example I could upload several projects at the same time, because in this configuration that I use the docker, I have to disable one, in order to activate another. Example project1.local and project2.local, how could you do it that way?
docker-compose.yml
version: '3.3'
services:
wordpress:
build: .
container_name: ${APP_NAME}-wordpress
restart: always
ports:
- 80:80
environment:
WORDPRESS_DB_HOST: ${DB_HOST}
WORDPRESS_DB_USER: ${DB_USER}
WORDPRESS_DB_PASSWORD: ${DB_PASS}
WORDPRESS_DB_NAME: ${DB_NAME}
WORDPRESS_TABLE_PREFIX: ${DB_TABLE_PREFIX}
WORDPRESS_CONFIG_EXTRA: |
/* Direct FTP */
define('FS_METHOD', 'direct');
volumes:
- ./src:/var/www/html/wp-content:rw
- ./config/php.ini:/usr/local/etc/php/conf.d/php.ini
depends_on:
- db
db:
image: mariadb
container_name: ${APP_NAME}-db
volumes:
- './database/db:/var/lib/mysql:delegated'
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
MYSQL_DATABASE: ${DB_NAME}
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASS}
restart: always
ports:
- '3306:3306'
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: ${APP_NAME}-phpmyadmin
volumes:
- ./config/phpmyadmin.ini:/usr/local/etc/php/conf.d/phpmyadmin.ini
environment:
PMA_HOST: ${DB_HOST}
PMA_PORT: 3306
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
ports:
- '8080:80'
links:
- db:db
Dockerfile
FROM wordpress
RUN chown -R www-data:www-data /var/www/html
There are some things that you can do:
1- Since you've declare:
ports:
- 80:80
You can't get to many wordpress at the same time with different docker-compose. So, you can delete the binding from your instance like this:
ports:
- 80
Doing it, you can make several docker-compose with different ports without worrying about the ports.
But there is another problem... Your database it's already up. So, in this case, if you want to use several docker-compose for each project you'll need another docker-compose for your database. So... the docker-compose solution is get another docker-compose for your database and in every docker-compose file add an external network:
With it, you can use the dns name as its always.
The other way is using the same template like this:
version: '3.3'
networks:
default:
external:
name: wordpresses
services:
wordpress_1:
build: .
container_name: ${APP_NAME}-wordpress
restart: always
ports:
- 80
environment:
WORDPRESS_DB_HOST: ${DB_HOST}
WORDPRESS_DB_USER: ${DB_USER}
WORDPRESS_DB_PASSWORD: ${DB_PASS}
WORDPRESS_DB_NAME: ${DB_NAME}
WORDPRESS_TABLE_PREFIX: ${DB_TABLE_PREFIX}
WORDPRESS_CONFIG_EXTRA: |
/* Direct FTP */
define('FS_METHOD', 'direct');
volumes:
- ./src/project1:/var/www/html/wp-content:rw
- ./config/php.ini:/usr/local/etc/php/conf.d/php.ini
depends_on:
- db
wordpress_2:
build: .
container_name: ${APP_NAME}-wordpress
restart: always
ports:
- 80
environment:
WORDPRESS_DB_HOST: ${DB_HOST}
WORDPRESS_DB_USER: ${DB_USER}
WORDPRESS_DB_PASSWORD: ${DB_PASS}
WORDPRESS_DB_NAME: ${DB_NAME}
WORDPRESS_TABLE_PREFIX: ${DB_TABLE_PREFIX}
WORDPRESS_CONFIG_EXTRA: |
/* Direct FTP */
define('FS_METHOD', 'direct');
volumes:
- ./src/project2:/var/www/html/wp-content:rw
- ./config/php.ini:/usr/local/etc/php/conf.d/php.ini
depends_on:
- db
db:
image: mariadb
container_name: ${APP_NAME}-db
volumes:
- './database/db:/var/lib/mysql:delegated'
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
MYSQL_DATABASE: ${DB_NAME}
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASS}
restart: always
ports:
- '3306:3306'
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: ${APP_NAME}-phpmyadmin
volumes:
- ./config/phpmyadmin.ini:/usr/local/etc/php/conf.d/phpmyadmin.ini
environment:
PMA_HOST: ${DB_HOST}
PMA_PORT: 3306
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
ports:
- '8080:80'
links:
- db:db
I know wordpress has some issues if you don't put the domain. In any case, you can use a NGINX in front of all wordpress as a reverse proxy like this Example.
Feel free to ask!
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 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?