I am completely new to Docker. I have a sonarqube image. I wrote a sample Docker Compose file and ran the image. Everything is working fine. Now I want to create 5-6 containers using Docker Compose.
How can I do this?
This is my sample YAML file:
version: '2'
services:
web:
build: .
ports:
- "9000:9000"
depends_on:
- my_image
my_image:
image: mySonarApp
I also would be interested in knowing if it is possible to create them only with my docker config file.
Just add more service definitions
version: '2'
services:
weba:
build: .
ports:
- "9000:9000"
weba:
build: .
ports:
- "9001:9000"
webc:
build: .
ports:
- "9002:9000"
You can use the scale command to create more instances of the service:
docker-compose scale web=6
Related
I have a Docker compose file setup which I am trying to push to ECR ( Elastic Container Registry ).
In order for me to Push it to ECR, I need to tag it with the URL of my ECR repo which is provided by AWS.
My docker-compose.yml file looks like this :-
version: '2'
services:
prometheus:
image: prom/prometheus
ports:
- '9090:9090'
container_name: prometheus
restart: always
volumes:
- './prometheus.yml:/etc/prometheus/prometheus.yml'
grafana:
image: grafana/grafana
ports:
- '3000:3000'
container_name: grafana
restart: always
depends_on:
- prometheus
volumes:
- './grafana.ini:/etc/grafana/grafana.ini'
But the AWS instructions tell me to build my app first using docker build ( I can do docker-compose up -d to build with docker compose ) and then it says to tag it with the URL of the registry.
Something like :-
docker tag myapp:url.ecr.us-west-1.amazonaws.com/myapp:latest
Where myapp is the name of the repo.
So I need a little bit of guidance as to how i can use this tag in my docker compose file?
Thank you.
You're looking to extend upon the image attribute. If you append a colon to the image, whatever comes after is built as the tag. Though note that this must be used in conjunction with build.
From the docs:
If you specify image as well as build, then Compose names the built image with the webapp and optional tag specified in image:
build: ./dir
image: webapp:tag
This results in an image named webapp and tagged tag, built from ./dir.
As such, you're likely looking for:
version: '2'
services:
prometheus:
build: ./dir
image: prom/prometheus:url.ecr.us-west-1.amazonaws.com/prom/prometheus:latest
ports:
- '9090:9090'
container_name: prometheus
restart: always
volumes:
- './prometheus.yml:/etc/prometheus/prometheus.yml'
grafana:
build: ./dir
image: grafana/grafana:url.ecr.us-west-1.amazonaws.com/grafana/grafana:latest
ports:
- '3000:3000'
container_name: grafana
restart: always
depends_on:
- prometheus
volumes:
- './grafana.ini:/etc/grafana/grafana.ini'
I tagged the running containers using :-
docker tag Image url.ecr.us-west-1.amazonaws.com/myapp:latest
And then i was able to do a docker push to ECR.
Hi I have three repos each of them having docker-compose files with respective ports and need to have one docker compose file that would stand all these containers up. Is it possible to do so? I am quite new to docker and have exhauseted all searches online. Thanks in advance
version: '3'
services:
api:
container_name: container-name
restart: always
build: ./
ports: "8085":8085
stub:
container_name: test-stub
restart: always
build: ./
ports: "8086":8086
In the build option you can specify which dockerfile to use :
version: "3"
services:
my_service:
container_name: my_container
build:
context: .
dockerfile: my_container.Dockerfile
I'm trying to setup the OSRM server on the top of Docker. I need to configure it using docker-compose.yml in side my micro-services project using .net core.
version: '3.4'
services:
test_web:
image: ${DOCKER_REGISTRY-}osrmweb
build:
context: .
dockerfile: OSRM_WEB/Dockerfile
ports:
- 1111
osrm-data:
image: irony/osrm5
volumes:
- /data
osrm:
image: irony/osrm5
volumes:
- osrm-data
ports:
- 5000:5000
command: ./start.sh Sweden http://download.geofabrik.de/europe/sweden-latest.osm.pbf
I have this docker-compose.yml file. When I run the docker-compose up There is no error but the container is Exited.
I cant see any response in this url.
https://localhost:5000/route/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219?overview=false
Any thing else I need to do in configurations? Any suggestions?
Is it possible to create services in a loop with docker-compose rather than typing all the services by hand? (See example below of creating 100 workers with appropriate ports)
version: '3'
services:
redis:
image: redis
worker1:
build: .
ports:
- "5001:5001"
worker2:
build: .
ports:
- "5002:5002"
worker3:
build: .
ports:
- "5003:5003"
...
worker100:
build: .
ports:
- "5100:5100"
You can probably do it with the --scale option, so if you run docker-compose up --scale worker=100 it should do exactly what you want.
The documentation for docker-compose up references this as follows:
--scale SERVICE=NUM Scale SERVICE to NUM instances. Overrides the
`scale` setting in the Compose file if present.
For development purposes I'm using docker compose in a VirtualBox running in OSX. To start the magic I run something like this (dkc=docker-compose)
$ dkc -f base.yml -f development.yml up -d --build
My docker compose files would be something like this:
base.yml
version: '2'
services:
padeltotal-app:
build:
context: ./padeltotal
dockerfile: Dockerfile.app
container_name: 'padeltotal-app'
links:
- padeltotal-mysql:db
ports:
- "9000:9000"
padeltotal-mysql:
build:
context: ./padeltotal
dockerfile: Dockerfile.db
container_name: 'padeltotal-mysql'
ports:
- "3306:3306"
nginx-lt:
extends:
file: common.yml
service: nginx
volumes_from:
- padeltotal-app
development:
version: '2'
services:
padeltotal-app:
volumes:
- ./padeltotal/code/src:/var/www/padeltotal/src
It's a PHP+MySql application
While I'm developing I'd like to have the volume with the PHP code I've mounted updated reflecting the changes from my ./padeltotal folder.
The default behaviour of the mounted volumen should be to reflect the HOST folder. However, in OSX is not working that way
I repeat, it's for development purposes, for production mode I don't even use docker compose
Is there a way to re-mount the volume?
What would be a different approach?