version: "1.0"
services:
es:
image: "elasticsearch:7.6.1"
container_name: myelasticsearch
ports:
- "9200:9200"
- "9300:9300"
environment:
- discovery.type=single-node
re:
image: redis
container_name: myredis
ports:
- "6379:6379"
rab:
image: "rabbitmq:3-management"
container_name: myrabbitmq
ports:
- "15672:15672"
- "5672:5672"
when i run docker-composer up it shows ERROR: Version "1.0" in ".\docker-compose.yml" is invalid. I am not finding why this error
There are three major versions of the docker-compose.yml file itself. You typically want the latest one
version: '3.7'
Version 1 was significant different from its successors: it put all of the service definitions at the top level, and didn't support top-level version: or services: keys. There are a number of other changes as well; if you need custom network configuration, Swarm support, or to specify the image name of a locally-built image, version 1 doesn't have any of these things.
version: "3.7"
services:
es:
image: "elasticsearch:7.6.1"
container_name: myelasticsearch
ports:
- "9200:9200"
- "9300:9300"
environment:
- discovery.type=single-node
re:
image: redis
container_name: myredis
ports:
- "6379:6379"
rabbitmq:
image: "rabbitmq:3-management"
container_name: myrabbitmq
ports:
- "15672:15672"
- "5672:5672"
Related
For past 3 days I have been trying to connect two docker containers generated by two separate docker-compose files.
I tried a lot of approaches none seem to be working. Currently after adding network to compose files, service with added network doesn't start. My goal is to access endpoint from another container.
Endpoint-API compose file:
version: "3.1"
networks:
test:
services:
mariadb:
image: mariadb:10.1
container_name: list-rest-api-mariadb
working_dir: /application
volumes:
- .:/application
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=list-api
- MYSQL_USER=list-api
- MYSQL_PASSWORD=root
ports:
- "8003:3306"
webserver:
image: nginx:stable
container_name: list-rest-api-webserver
working_dir: /application
volumes:
- .:/application
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8005:80"
networks:
- test
php-fpm:
build: docker/php-fpm
container_name: list-rest-api-php-fpm
working_dir: /application
volumes:
- .:/application
- ./docker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
Consumer compose file:
version: "3.1"
networks:
test:
services:
consumer-mariadb:
image: mariadb:10.1
container_name: consumer-service-mariadb
working_dir: /consumer
volumes:
- .:/consumer
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=consumer
- MYSQL_USER=consumer
- MYSQL_PASSWORD=root
ports:
- "8006:3306"
consumer-webserver:
image: nginx:stable
container_name: consumer-service-webserver
working_dir: /consumer
volumes:
- .:/consumer
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8011:80"
networks:
- test
consumer-php-fpm:
build: docker/php-fpm
container_name: consumer-service-php-fpm
working_dir: /consumer
volumes:
- .:/consumer
- ./docker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
Could someone tell me best way of accessing API container from within consumer? I'm loosing my mind on this one.
Your two
networks:
test:
don't refer to the same network, but they are independent and don't talk to each other.
What you could do is having an external and pre-existing network that both compose file can talk and share. You can do that with docker network create, and then refer to that in your compose files with
networks:
default:
external:
name: some-external-network-here
My docker-compose.yml looks like the below. When i run docker-compose up I get the below error.
ERROR: In file './docker-compose.yml', the service name True must be a quoted string, i.e. 'True'.
version: '3'
services:
db:
restart: always
image: postgres:9.6-alpine
container_name: pleroma_postgres
networks:
- pleroma
volumes:
- ./postgres:/var/lib/postgresql/data
web:
build: .
image: pleroma
container_name: pleroma_web
restart: always
environment:
- VIRTUAL_HOST=<myplaceholderhost>
- VIRTUAL_PORT=4000
- LETSENCRYPT_HOST=<myplaceholderhost>
- LETENCRYPT_EMAIL=<myplaceholderemail>
expose:
- "4000"
volumes:
- ./uploads:/pleroma/uploads
depends_on:
- db
nginx:
image: jwilder/nginx-proxy
container_name: nginx
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- /apps/docker-articles/nginx/vhost.d:/etc/nginx/vhost.d
- /apps/docker-articles/nginx/certs:/etc/nginx/certs:ro
- /apps/docker-articles/nginx/html:/usr/share/nginx/html
restart: always
ports:
- "80:80"
- "443:443"
labels:
com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: "true"
networks:
- pleroma
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion:v1.5
container_name: letsencrypt
volumes_from:
- nginx
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /apps/docker-articles/nginx/vhost.d:/etc/nginx/vhost.d
- /apps/docker/articles/nginx/certs:/etc/nginx/certs:rw
- /apps/docker-articles/nginx/html:/usr/share/nginx/html
networks:
pleroma:
My docker version is
Docker version 18.06.1-ce, build e68fc7a
My docker compose version is
docker-compose version 1.23.1, build b02f1306
Running CoreOS version 1911.3.0
I ended up resolving this issue by modifying the nginx and letsencrypt portions of my docker-compose.yml file to be as follows.
nginx:
image: jwilder/nginx-proxy
container_name: nginx
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- /apps/docker-articles/nginx/vhost.d:/etc/nginx/vhost.d
- /apps/docker-articles/nginx/certs:/etc/nginx/certs:ro
- /apps/docker-articles/nginx/html:/usr/share/nginx/html
restart: always
ports:
- "80:80"
- "443:443"
labels:
- "NGINX_PROXY_CONTAINER=true"
networks:
- pleroma
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion:v1.5
container_name: letsencrypt
environment:
- NGINX_PROXY_CONTAINER=true
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /apps/docker-articles/nginx/vhost.d:/etc/nginx/vhost.d
- /apps/docker/articles/nginx/certs:/etc/nginx/certs:rw
- /apps/docker-articles/nginx/html:/usr/share/nginx/html
It seems "volumes_from" is deprecated in docker-compose v3. As well as I had forgotted quotes around my label and needed to set my environment within letsencrypt.
in CentOS env your .yml file directory must be /usr/local/bin
Here is my docker-compose.yml file
version: '3'
services:
mongodb:
image: hedge-mongo:1.0
container_name: mongodb
ports:
- "27017:27017"
networks:
- appNetwork
service-A:
image: service-A:1.0
container_name: service-A
ports:
- "3030:3030"
networks:
- appNetwork
depends_on:
- mongodb
service-B:
image: service-B:1.0
container_name: service-B
ports:
- "4200:4200"
networks:
- appNetwork
service-C:
image: service-C:1.0
container_name: service-C
ports:
- "8082:8082"
networks:
- appNetwork
networks:
appNetwork:
external: true
In above file service-A and service-C are trying to connect to MongoDB
Issue:
In above file service-A and service-C are getting connected to MongoDB before MongoDB is up
so, I want to run service-A and service-C after MongoDB is up completely.
I tried adding depends-on for service-A and service-C
service-A:
image: service-A:1.0
container_name: service-A
ports:
- "3030:3030"
networks:
- appNetwork
depends_on:
- mongodb
service-C:
image: service-C:1.0
container_name: service-C
ports:
- "8082:8082"
networks:
- appNetwork
depends_on:
- mongodb
still, it did not work out sometimes it works sometimes it doesn't so it's not reliable.
I want to make sure my other services are up only after MongoDB is up.
that is a race condition, you're services is trying to start at the same time, thats why you got a result of sometimes it success and sometimes its not.. here an example on how to solve the race condition..
example 1
example 2
I am encountering some conflicts between the traefik.frontend.redirect and PathPrefixStrip. the docker-compose.yml file below always routes www.mysite.nl/adminer to the wordpress container. If I omit the redirect rules it works correctly and i get routed to the adminer instance. How can I make these rules work together?
Drilled down docker-comose.yml:
version: '3'
services:
wordpress:
image: wordpress:latest
restart: $RESTART
container_name: ${COMPOSE_PROJECT_NAME}_wp
depends_on:
- mysql
networks:
- web
labels:
- 'traefik.backend=$COMPOSE_PROJECT_NAME'
- 'traefik.entrypoint=https'
- 'traefik.enable=true'
- 'traefik.frontend.rule=Host:mysite.nl, www.mysite.nl, cdn.mysite.net'
# omitting these rules make the adminer instance reachable
- 'traefik.frontend.redirect.regex=^https?://mysite.nl/(.*)'
- 'traefik.frontend.redirect.replacement=https://www.mysite.nl/$${1}'
mysql:
image: mysql:latest
restart: $RESTART
container_name: ${COMPOSE_PROJECT_NAME}_db
networks:
- web
adminer:
image: adminer:4.6.2
restart: $RESTART
container_name: ${COMPOSE_PROJECT_NAME}
depends_on:
- mysql
networks:
- web
labels:
- 'traefik.backend=${COMPOSE_PROJECT_NAME}_adminer'
- 'traefik.entrypoint=https'
- 'traefik.enable=true'
- 'traefik.frontend.rule=Host:www.mysite.nl;PathPrefixStrip:/adminer'
networks:
web:
external:
name: traefik_${COMPOSE_PROJECT_NAME}_web
The issue you are running into is due to overlapping rules.
The request www.mysite.nl/adminer
Matches both:
traefik.frontend.rule=Host:mysite.nl, www.mysite.nl, cdn.mysite.net
and traefik.frontend.rule=Host:www.mysite.nl;PathPrefixStrip:/adminer
Therefore Traefik does not know which to route requests to.
Use the traefik.frontend.priority label to set an order for matching (from https://docs.traefik.io/configuration/backends/docker/#on-containers)
With help from Daniel Tomcej i came to the following working docker-compose.yml. You have to set the priority explicitly on both containers.
version: '3'
services:
wordpress:
image: wordpress:latest
restart: $RESTART
container_name: ${COMPOSE_PROJECT_NAME}_wp
depends_on:
- mysql
networks:
- web
labels:
- 'traefik.backend=$COMPOSE_PROJECT_NAME'
- 'traefik.entrypoint=https'
- 'traefik.enable=true'
- 'traefik.frontend.rule=Host:mysite.nl, www.mysite.nl, cdn.mysite.net'
- 'traefik.frontend.redirect.regex=^https?://mysite.nl/(.*)'
- 'traefik.frontend.redirect.replacement=https://www.mysite.nl/$${1}'
- 'traefik.frontend.priority=5'
mysql:
image: mysql:latest
restart: $RESTART
container_name: ${COMPOSE_PROJECT_NAME}_db
networks:
- web
adminer:
image: adminer:4.6.2
restart: $RESTART
container_name: ${COMPOSE_PROJECT_NAME}
depends_on:
- mysql
networks:
- web
labels:
- 'traefik.backend=${COMPOSE_PROJECT_NAME}_adminer'
- 'traefik.entrypoint=https'
- 'traefik.enable=true'
- 'traefik.frontend.rule=Host:www.mysite.nl;PathPrefixStrip:/adminer'
- 'traefik.frontend.priority=20'
networks:
web:
external:
name: traefik_${COMPOSE_PROJECT_NAME}_web
This is how my docker-compose.yml file looks like. As you can see, there is a nginx server, a mongoDB, the main application and for testing a nightwatch and selenium container.
nginx:
container_name: 'nginx'
image: 'nginx:1.11'
restart: 'always'
ports:
- '80:80'
- '443:443'
volumes:
- '/opt/nginx/conf.d:/etc/nginx/conf.d:ro'
- '/opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro'
- '/etc/letsencrypt:/etc/letsencrypt'
- '/opt/nginx/www:/var/www:ro'
links:
- 'app'
nightwatch:
container_name: nightwatch
image: 'registry.example.com/project/core:nightwatch'
links:
- selenium
stdin_open: true
tty: true
selenium:
container_name: selenium
image: selenium/standalone-chrome
ports:
- 4444:4444
links:
- app
db:
container_name: db
image: 'mongo:3.4'
restart: 'always'
volumes:
- '/opt/mongo/project/prod:/data/db'
app:
container_name: app
image: 'registry.example.de/project/core:latest'
restart: always
links:
- 'db'
environment:
- ROOT_URL=https://example.com
- MONGO_URL=mongodb://db/db
You can also see, that I'm still using version 1 and I want to upgrade to current version (3). And there are a few problems for converting the file.
For example I do not understand the network option which should be used instead of the deprecated link to get access to containers.
In the nightwatch container I'm running a script like
module.exports = {
'start application': function(browser) {
browser
.url('http://app') // <--
.waitForElementVisible('body', 10000)
.getTitle(function(result) {
this.assert.equal(typeof result, 'string')
})
},
}
So I need to get access to the app container via nightwatch, which also needs selenium. The main app needs of course the db.
I need some help converting to version 3:
version: '3'
services:
nginx:
...
nightwatch:
...
This should be enough:
version: "3"
services:
nginx:
container_name: 'nginx'
image: 'nginx:1.11'
restart: 'always'
ports:
- '80:80'
- '443:443'
volumes:
- '/opt/nginx/conf.d:/etc/nginx/conf.d:ro'
- '/opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro'
- '/etc/letsencrypt:/etc/letsencrypt'
- '/opt/nginx/www:/var/www:ro'
links:
- app
nightwatch:
container_name: nightwatch
image: 'registry.example.com/project/core:nightwatch'
links:
- selenium
stdin_open: true
tty: true
selenium:
container_name: selenium
image: selenium/standalone-chrome
ports:
- 4444:4444
links:
- app
db:
container_name: db
image: 'mongo:3.4'
restart: 'always'
volumes:
- '/opt/mongo/project/prod:/data/db'
app:
container_name: app
image: 'registry.example.de/project/core:latest'
restart: always
links:
- db
environment:
- ROOT_URL=https://example.com
- MONGO_URL=mongodb://db/db
You don't need to configure extra networks than the default provided by compose.
Linking containers is still configured as so. Try this:
version: "3"
services:
abc:
image: ubuntu
command: tail -f /dev/null
cde:
image: busybox
command: ping abc
links:
- abc