What is wrong with this docker-compose.yml file - docker

I am trying to install gitlab ce with docker compose file. I have had lots of permissions problem with bind volumes. I would like to try names volumes. Following is my file.
web:
image: 'gitlab/gitlab-ce:latest'
container_name: 'gitlab'
restart: always
hostname: 'gitlab.xxxx.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'https://gitlab.xxxx.com'
ports:
- '10080:80'
- '10443:443'
- '10022:22'
volumes:
- gitlab_config:/etc/gitlab
- gitlab_log:/var/log/gitlab
- gitlab_data:/var/opt/gitlab
volumes:
gitlab_config:
external: true
gitlab_log:
external: true
gitlab_data:
external: true
I receive following error:
docker-compose up -d
ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for volumes: 'gitlab_data'
Volumes have been created previously with docker volume create command
UPDATE : Based the solution by Ganesh Satpute, I submit the working/tested file below. Someone may need it since gitlab page does not provide it. Thank you "Ganesh".
---
version: "2.4"
services:
web:
image: 'gitlab/gitlab-ce:latest'
container_name: 'gitlab'
restart: always
hostname: 'gitlab.xxxx.com'
environment:
GITLAB_OMNIBUS_CONFIG: 'https://gitlab.xxxx.com'
ports:
- '10080:80'
- '10443:443'
- '10022:22'
volumes:
- gitlab_config:/etc/gitlab
- gitlab_log:/var/log/gitlab
- gitlab_data:/var/opt/gitlab
volumes:
gitlab_config:
external: true
gitlab_log:
external: true
gitlab_data:
external: true

I modified your docker-compose.yml with this
version: "2.4"
services:
web:
image: 'gitlab/gitlab-ce:latest'
container_name: 'gitlab'
restart: always
hostname: 'gitlab.xxxx.com'
environment:
GITLAB_OMNIBUS_CONFIG: 'https://gitlab.xxxx.com'
ports:
- '10080:80'
- '10443:443'
- '10022:22'
volumes:
- gitlab_config:/etc/gitlab
- gitlab_log:/var/log/gitlab
- gitlab_data:/var/opt/gitlab
volumes:
gitlab_config:
external: true
gitlab_log:
external: true
gitlab_data:
external: true

You can always check by running docker-compose config to check if the config file is valid or not. If not google the errors and also check few examples online.

Related

How can I fix this issue with Yaml file?

Hi I am trying to run docker-compose build --no-cache but I keep getting errors.
yaml.parser.ParserError: while parsing a block mapping
in ".\docker-compose.yml", line 1, column 1
expected <block end>, but found '<block mapping start>'
in ".\docker-compose.yml", line 2, column 5
docker-compose.yml:
Please help me to to format this I looked online but I couldn't find any linter that could do this I keep getting errors.
Thanks.
This is my docker composer file:
s is my docker file docker-compose.yml
version: '3'
services:
#PHP-FPM service
app:
build:
context: .
dockerfile: Dockerfile
container_name: store
restart: unless-stopped
tty: true
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker-files/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
-app-network
#Nginix service
webserver:
image: nginx-alpine
container_name: store-webserver
restart: unless-stopped
tty: true
ports:
- "8100:80"
- "8143:443"
volumes:
- ./:/var/www
- ./docker-files/nginx/conf.d:/etc/nginx/conf.d/
networks:
-app-network
#MariaDB service
db:
image: mariadb:10.5.6
container_name: store-mariadb
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: store
MYSQL_USER: store
MYSQL_PASSWORD: root
volumes:
- mariadbData:/var/lib/mysql
- ./docker-files/mariadb/my.cnf:/etc/mysql/my.cnf
networks:
-app-network
#Volumes
volumes:
mariadbData:
driver: local
#Networks
networks:
app-network:
driver: bridge
I have noticed some spacing issues on your YAML file, one of them is that the version and services sections are not on the same level, you have to know that docker-compose files and YAML have a strict syntax and a spacing might ruin everything for you here is a fix to your compose file, make sure to learn and read more about docker-compose documentation.
Not sure what's the behavior of your environment but here is a correct YAML syntax for your example:
version: '3'
services:
#PHP-FPM service
app:
build:
context: .
dockerfile: Dockerfile
container_name: store
restart: unless-stopped
tty: true
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker-files/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginix service
webserver:
image: nginx-alpine
container_name: store-webserver
restart: unless-stopped
tty: true
ports:
- "8100:80"
- "8143:443"
volumes:
- ./:/var/www
- ./docker-files/nginx/conf.d:/etc/nginx/conf.d/
networks:
- app-network
#MariaDB service
db:
image: mariadb:10.5.6
container_name: store-mariadb
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: store
MYSQL_USER: store
MYSQL_PASSWORD: root
volumes:
- mariadbData:/var/lib/mysql
- ./docker-files/mariadb/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#Volumes
volumes:
mariadbData:
driver: local
#Networks
networks:
app-network:
driver: bridge

The Compose filedocker-compose.yml' is invalid because environment contains an invalid type, it should be an object, or an array

I found this docker compose container on an asian site, and was trying to run it, and then I got the following. I had to modify the docker compose file because there were duplicated characters. I'm not sure why this won't run, and i have looked on stackoverflow for other issues, but none resolved my issue.
The docker compose file is as follows:
---
version: '3.5'
services:
wowonder-web:
container_name: wowonder-web
image: webdevops/php-apache:debian-10
environment:
-WEB_DOCUMENT_ROOT=/app
-PHP_MEMORY_LIMIT=1024M
-PHP_MAX_EXECUTION_TIME=7200
-PHP_POST_MAX_SIZE=10240M
-PHP_UPLOAD_MAX_FILESIZE=10240M
-FPM_MAX_REQUESTS=500
-FPM_PM_MAX_CHILDREN=20
-FPM_PM_START_SERVERS=10
-FPM_PM_MIN_SPARE_SERVERS=5
-FPM_PM_MAX_SPARE_SERVERS=15
volumes:
- /opt/wowonder/app:/appwowonder:/app
restart: unless-stopped
wowonder-db:
container_name: wowonder-db
image: mariadb
environment:
-MYSQL_ROOT_PASSWORD="wowonder"
-MYSQL_PASSWORD="wowonder"
-MYSQL_DATABASE="wowonder"
-MYSQL_USER="wowonder"
volumes:
- /docker/Databases/wowonder:/var/lib/mysqldb
command: --sql-mode="NO_ENGINE_SUBSTITUTION"
restart: unless-stopped
networks:
default:
external:
name: imlala
A few mistypes (check this online YAML validator in the future):
First, as #DavidMaze noted, to create a YAML array in a docker-compose file the most popular option is to create a new line for each element and start with a hyphen and a space right after it, you can browse other options in this SO thread
environment:
- WEB_DOCUMENT_ROOT=/app
- PHP_MEMORY_LIMIT=1024M
- PHP_MAX_EXECUTION_TIME=7200
- PHP_POST_MAX_SIZE=10240M
- PHP_UPLOAD_MAX_FILESIZE=10240M
- FPM_MAX_REQUESTS=500
- FPM_PM_MAX_CHILDREN=20
- FPM_PM_START_SERVERS=10
- FPM_PM_MIN_SPARE_SERVERS=5
- FPM_PM_MAX_SPARE_SERVERS=15
Second, your command for wowonder-db was too much indented, taking it a step back fixed the issue.
volumes:
- /docker/Databases/wowonder:/var/lib/mysqldb
command: --sql-mode="NO_ENGINE_SUBSTITUTION"
restart: unless-stopped
Complete and valid compose file:
---
version: '3.5'
services:
wowonder-web:
container_name: wowonder-web
image: webdevops/php-apache:debian-10
environment:
- WEB_DOCUMENT_ROOT=/app
- PHP_MEMORY_LIMIT=1024M
- PHP_MAX_EXECUTION_TIME=7200
- PHP_POST_MAX_SIZE=10240M
- PHP_UPLOAD_MAX_FILESIZE=10240M
- FPM_MAX_REQUESTS=500
- FPM_PM_MAX_CHILDREN=20
- FPM_PM_START_SERVERS=10
- FPM_PM_MIN_SPARE_SERVERS=5
- FPM_PM_MAX_SPARE_SERVERS=15
volumes:
- /opt/wowonder/app:/appwowonder:/app
restart: unless-stopped
wowonder-db:
container_name: wowonder-db
image: mariadb
environment:
- MYSQL_ROOT_PASSWORD="wowonder"
- MYSQL_PASSWORD="wowonder"
- MYSQL_DATABASE="wowonder"
- MYSQL_USER="wowonder"
volumes:
- /docker/Databases/wowonder:/var/lib/mysqldb
command: --sql-mode="NO_ENGINE_SUBSTITUTION"
restart: unless-stopped
networks:
default:
external:
name: imlala

Need to up my docker file in ubuntu "docker-compose up -d"

services:
postgres:
container_name: 'lh-postgres'
image: 'postgres:13'
environment:
POSTGRES_PASSWORD: root
redis:
container_name: 'lh-redis'
image: 'redis:6'
nginx:
container_name: 'lh-nginx'
build: ./nginx
depends_on:
- php-fpm
volumes:
- ./src/lh-app:/var/www/html/app
- ./src/lh-api:/var/www/html/api
ports:
- "80:80"
- "443:443"
php-fpm:
container_name: 'lh-php'
image: docker.io/bitnami/php-fpm:8.0
user: '1000:1000'
build:
context: ./php-fpm
args:
- PHP_ENV= development
depends_on:
- postgres
- redis
volumes:
- ./src/lh-app:/var/www/html/app
- ./src/lh-api:/var/www/html/api
ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services: 'postgres'
getting this error
I think you are missing some ENV vars.
This is our docker-compose.yml for Postgres
version: '3.9'
services:
db:
image: postgres:latest
restart: "no"
container_name: db
volumes:
- ./database:/var/lib/postgresql/data
ports:
- "8002:5432"
environment:
POSTGRES_PASSWORD: verySecurePassword34058
POSTGRES_USER: root
POSTGRES_DB: myDatabase
networks:
default:
external: true
name: our-network
Other parts of the application, (like Redis, the NodeJS App, etc) are in other docker-compose.yml files, But since they share the same network, they talk to each other.
You have not mentioned version in docker-composer.yml
version: '2'
services:
postgres:
container_name: 'lh-postgres'
image: 'postgres:13'
environment:
POSTGRES_PASSWORD: root
redis:
container_name: 'lh-redis'
image: 'redis:6'
You should include your docker and docker-compose version in the querstion to help us answer you.
It would also be wise to define the version: 'x' element at the top of your compose file.
You may be suffering from an old version of the cli, akin to this question:
docker-compose : Unsupported config option for services service: 'web'

Isolate containers on the jwilder/nginx-proxy network

I'm using jwilder/nginx-proxy to host multiple (web)apps from a single server. This is working great except that all services can communicate with each other because they are all on the same network because that is required for the proxy to work.
Proxy docker-compose.yaml
version: "3"
services:
nginx-proxy:
image: jwilder/nginx-proxy:alpine
container_name: nginx-proxy
labels:
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"
ports:
- "80:80"
- "443:443"
volumes:
- ./data/certs:/etc/nginx/certs:ro
- ./data/nginx/vhost.d:/etc/nginx/vhost.d
- ./data/share/nginx/html:/usr/share/nginx/html
- /var/run/docker.sock:/tmp/docker.sock:ro
restart: always
letsencrypt-proxy:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: letsencrypt-proxy
depends_on:
- nginx-proxy
volumes:
- ./data/nginx/vhost.d:/etc/nginx/vhost.d
- ./data/share/nginx/html:/usr/share/nginx/html
- ./data/certs:/etc/nginx/certs:rw
- /var/run/docker.sock:/var/run/docker.sock:ro
restart: always
networks:
default:
external:
name: nginx-proxy
App 1 docker-compose.yaml
version: "3"
services:
app:
image: nginx:latest
depends_on:
- db
- cache
expose:
- 80
volumes:
- ./application:/var/www/html
restart: always
working_dir: /var/www/html
environment:
VIRTUAL_HOST: app1.example.com
LETSENCRYPT_HOST: app1.example.com
LETSENCRYPT_EMAIL: user#example.com
cache:
image: redis:alpine
restart: always
volumes:
- cachedata:/data
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: rootpasswd
MYSQL_DATABASE: database_name
MYSQL_USER: database_user
MYSQL_PASSWORD: database_passwd
volumes:
- dbdata:/var/lib/mysql
networks:
default:
external:
name: nginx-proxy
volumes:
dbdata:
driver: local
cachedata:
driver: local
App 2 docker-compose.yaml
version: "3"
services:
app:
image: nginx:latest
depends_on:
- db
- cache
expose:
- 80
volumes:
- ./application:/var/www/html
restart: always
working_dir: /var/www/html
environment:
VIRTUAL_HOST: app2.example.com
LETSENCRYPT_HOST: app2.example.com
LETSENCRYPT_EMAIL: user#example.com
cache:
image: redis:alpine
restart: always
volumes:
- cachedata:/data
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: rootpasswd
MYSQL_DATABASE: database_name
MYSQL_USER: database_user
MYSQL_PASSWORD: database_passwd
volumes:
- dbdata:/var/lib/mysql
networks:
default:
external:
name: nginx-proxy
volumes:
dbdata:
driver: local
cachedata:
driver: local
With this setup both applications will use de db and cache instance of App 1. The only way to solve that is to give those services unique names like app_1_db and app_2_db. But then App 1 is still able to connect to the app_2_db which I would like to prevent.
Is there a way to isolate all services within their docker-composer.yaml file and still use the nginx proxy?
Docker version 18.09.0, build 4d60db4
docker-compose version 1.21.2, build a133471
You can connect only the app(nginx) container from your apps to the nginx-proxy network. The only edit needed should be in the app's docker-compose:
version: '3'
services:
app:
networks:
- default
- nginx-proxy
networks:
nginx-proxy:
external: true
That way the app service will be connected to nginx-proxy and default networks at the same time. (If you omit networks key, service is always connected to the default network)
Resolving service names to containers ip's then works as expected as long as no container can see (across all networks it's connected to) two containers with same service name.
If you want even more isolation, you can create nginx-proxy network for every app.
So in your nginx-proxy docker-compose you will have:
version: "3"
services:
nginx-proxy:
networks:
- default
- nginx-proxy_app1
- nginx-proxy_app2
# letsencrypt-proxy service doesn't have to have networks key
networks:
nginx-proxy_app1:
external: true
nginx-proxy_app2:
external: true
and in your apps:
version: '3'
services:
app:
networks:
- default
- nginx-proxy_app1
networks:
nginx-proxy_app1:
external: true
and
version: '3'
services:
app:
networks:
- default
- nginx-proxy_app2
networks:
nginx-proxy_app2:
external: true
That way in every "proxy" network there is only one (if you are not using docker-compose scaling) app container and the nginx-proxy container.
More reading:
https://docs.docker.com/compose/networking/
https://docs.docker.com/network/overlay/#operations-for-standalone-containers-on-overlay-networks

Unsupported config option for services.volumes

Trying to setup docker for the first time and I'm running into a problem with volumes. I feel pretty confident that the spacing and formatting in the .yml is correct at this point.
I've tried versions 3, 3.1, 3.2, 3.3 and 3.4. All are getting the same error message (below)
Unsupported config option for services.volumes: 'db2_prod'
version: '3'
services:
liberty:
image: liberty:${liberty_tag}
ports:
- "${liberty_ip}:9080:9080"
- "${liberty_ip}:9443:9443"
restart: always
apache:
image: webapp:${apache_tag}
ports:
- "${apache_ip}:80:80"
- "${apache_ip}:443:443"
restart: always
db2:
image: db2:${db2_tag}
ports:
- "${db2_ip}:50000:50000"
stdin_open: true
tty: true
restart: always
volumes:
- db2_prod:/database/stagg3
volumes:
db2_prod:
volumes needs to be at the same indentation with services i.e
services:
#...
volumes:
db2_prod:
version: '3.7'
services:
web:
build: .
command: python /code/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- 8000:8000
depends_on:
- db
db:
image: postgres:11
volumes:
- postgres_data:/var/lib/postgresql/data/
volumes:
postgres_data:
observe that version, services and volumes have same indent level. Moreover use spacebar for indentation, use of tab may create problem.

Resources