How to build docker images in parallel using docker-compose? - docker

I have the following docker-compose:
version: "3.7"
services:
base:
build:
context: .
dockerfile: ./dockerfiles/Dockerfile
image: myapp/php7.0.8
volumes:
- "./www:/var/www/html"
develop:
build:
context: .
dockerfile: ./dockerfiles/Dockerfile_develop
image: myapp/php7.0.8-dev
volumes:
- "./www:/var/www/html"
nginx:
image: nginx:alpine
ports:
- 7880:7880
- 7881:7881
links:
- "develop:develop"
- "base:base"
volumes:
- "./www:/var/www/html"
- "./dist/nginx.conf:/etc/nginx/nginx.conf:ro"
That each docker image is being built. Both develop and base are being built with seperate dependencies without depending to each other. So how I can use docker-compose in order to build both base and develop in parallel in order to speed up the process?

Related

Docker Compose ports are being ignored on up

This is my Docker Compose file containing 4 api containers:
version: '3.4'
services:
api1.api:
image: ${DOCKER_REGISTRY-}api1
build:
context: .
dockerfile: Api1.Api/Dockerfile
networks:
- dev-network
ports:
- "62000:443"
- "62001:80"
api2.api:
image: ${DOCKER_REGISTRY-}api2
build:
context: .
dockerfile: Api2.Api/Dockerfile
networks:
- dev-network
ports:
- "62002:443"
- "62003:80"
api3.api:
image: ${DOCKER_REGISTRY-}api3
build:
context: .
dockerfile: Api3.Api/Dockerfile
networks:
- dev-network
ports:
- "62004:443"
- "62005:80"
api4.api:
image: ${DOCKER_REGISTRY-}api4
build:
context: .
dockerfile: Api4.Api/Dockerfile
networks:
- dev-network
ports:
- "62006:443"
- "62007:80"
networks:
dev-network:
name: dev-network
I have set the ports but when I run docker-compose up -d, the results are that either 1 or 2 of the apis will have the specified ports only. The rest will be randomly generated or even blank.
I have to manually restart that container before it generates a random port.
Am I missing a command or step? How can I get my docker-compose to follow the ports that have been set?

Gitlab CI shell runner fails with docker-compose up

I'm trying to start multiple docker containers with a wsl shell runner. After running
compose_job:
tags:
- wsl
stage: compose
script:
- cd /pathToComposeFile
- docker-compose up
dependencies:
- pull_job
the runner excited with following error:
$ docker-compose up
docker: invalid reference format: repository name must be lowercase.
the docker-compose.yml is:
version: '3'
services:
cron:
build: cron/.
container_name: cron
image: cron_image
ports:
- 6040:6040
The referenced images are all written in lowercase and the same command excited as expected
if run manually. I already checked that docker-compose is accessible and that the docker-compose.yml is readable. How can I resolve this issue? Thank you in advance!
I think service_name, container_name and env must be lowercase.
Look like
version: '3'
services:
perihubapi:
build:
context: api/.
args:
EXTERNAL: ${external}
FASERVICES: ${faservices}
container_name: perihubapi
image: peri_hub_api_image
ports:
- 6020:6020
networks:
- backend
volumes:
- peridigm_volume:/app/peridigmJobs
- paraView_volume:/app/paraView
- secrets:/app/certs
perihubgui:
build: gui/.
container_name: perihubgui
image: peri_hub_gui_image
ports:
- 6010:6010
networks:
- backend
volumes:
- secrets:/app/certs
peridigm:
build:
context: peridigm/.
args:
GITLAB_USER: ${gitlab_user}
GITLAB_TOKEN: ${gitlab_token}
PERIDOX: ${peridox}
container_name: peridigm
image: peridigm_image
ports:
- 6030:6030
networks:
- backend
volumes:
- peridigm_volume:/app/peridigmJobs
paraview:
build:
context: paraview/.
container_name: paraview
image: paraview_image
volumes:
- paraView_volume:/app/paraView
cron:
build: cron/.
container_name: cron
image: cron_image
ports:
- 6040:6040
networks:
- backend
networks:
backend:
driver: bridge
volumes:
peridigm_volume:
paraView_volume:
secrets:
external: true

How to use single docker compose to build containers in different directories

I want to spin up two containers when I do docker-compose up
I have two folders API and front. Each has a Dockerfile and docker-compose file. currently, I have to do docker-compose up for each app.
like below
- api
- docker-compose.yml
- Dockerfile
- front
- docker-compose.yml
- Dockerfile
I want to have one docker-compose.yml to manage two containers like below.
- docker-compose.yml
- api
- Dockerfile
- front
- Dockerfile
api docker-compose
version: '3'
services:
api:
build: .
command: pipenv run start
image : data-tracker-backend
volumes:
- .:/api/
ports:
- "8000:8000"
front docker-compose
version: '3'
services:
web:
build: .
command: npm start
image : data-tracker-front
volumes:
- .:/front/
ports:
- "5000:5000"
I want to have something like
version: '3'
services:
api:
build: .
command: pipenv run start
image : data-tracker-backend
volumes:
- .:/api/
ports:
- "8000:8000"
front:
build: .
command: npm start
image : data-tracker-front
volumes:
- .:/front/
ports:
- "5000:5000"
help to access the command from the different working directories.
You can change the build directory and the volumes one.
version: '3'
services:
api:
build: ./api
volumes:
- ./api:/api
# the rest of your commands...
front:
build: ./front
volumes:
- ./front:/front
# the rest of your commands...
My suggestion though is to read the guidelines. It's plenty of information and tutorials there.
You can try to use build context and dockerfile as shown below
- docker-compose.yml
- api
- Dockerfile
- front
- Dockerfile
version: '3'
services:
api:
build:
context: api
dockerfile: Dockerfile
command: pipenv run start
image : data-tracker-backend
volumes:
- .:/api/
ports:
- "8000:8000"
front:
build:
context: front
dockerfile: Dockerfile
command: npm start
image : data-tracker-front
volumes:
- .:/front/
ports:
- "5000:5000"

Jasper Server Community Edition on Docker

Tibco has made the Dockerfile and supporting scripts for running TIBCO JasperReportsĀ® Server in a Docker container. What do I need to change in these files to support the Community Edition?
https://github.com/TIBCOSoftware/js-docker/
Thanks.
You can also alternatively use the JasperReports Server docker from bitnami, which uses the CE version of the server:
https://github.com/bitnami/bitnami-docker-jasperreports
You need to make changes to the js-docker Docker files, shell scripts and roll your own Docker Compose file, for example:
version: '3.7'
services:
postgres:
container_name: postgres
build:
context: ./services/postgres
dockerfile: Dockerfile
ports:
- "5432:5432"
volumes:
- .:/var/lib/postgresql/data
env_file: ./services/postgres/postgres.env
pgadmin:
container_name: pgadmin
build:
context: ./services/pgadmin
dockerfile: Dockerfile
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-admin#serendipity.org.au}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-secret}
ports:
- "${PGADMIN_PORT:-5050}:80"
volumes:
- .:/root/.pgadmin
jasperreports-server:
container_name: jasperreports-server
build:
context: ./services/jasperreports-server
dockerfile: Dockerfile
ports:
- "11001:8080"
- "11443:8443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./license:/usr/local/share/jasperserver/license
- ./keystore:/usr/local/share/jasperserver/keystore
env_file: ./services/jasperreports-server/jasperreports-server.env
environment:
- DB_HOST=postgres
depends_on:
- jasperreports-server-cmdline
command: ["/wait-for-container-to-exit.sh", "jasperreports-server-cmdline", "-t" , "30", "--", "/entrypoint-ce.sh", "run"]
jasperreports-server-cmdline:
container_name: jasperreports-server-cmdline
build:
context: ./services/jasperreports-server
dockerfile: Dockerfile-cmdline
volumes:
- ./license:/usr/local/share/jasperserver/license
- ./keystore:/usr/local/share/jasperserver/keystore
env_file: ./services/jasperreports-server/jasperreports-server.env
environment:
- DB_HOST=postgres
- JRS_LOAD_SAMPLES=true
depends_on:
- postgres
command: ["/wait-for-it.sh", "postgres:5432", "-t" , "30", "--", "/entrypoint-cmdline-ce.sh", "init"]
Take a look at this example GitHub repo: https://github.com/Robinyo/serendipity-api/tree/master/projects/spring-boot/server/services/jasperreports-server

Make a global variable od "extra_hosts" in docker-compose

Lets suppose that I have got a ten services in docker-compose and every this service need the same extra_hosts with a four records.
I would like to define extra_hosts once and only include it to every service.
Is it possible?
version: '3.7'
services:
web:
build:
context: ./apache
dockerfile: dockerfile_apache2
image: debian:latest
container_name: hsthttp1
extra_hosts:
- "somehost1:162.242.195.82"
- "somehost2:162.242.195.83"
- "somehost3:162.242.195.84"
- "somehost4:162.242.195.85"
web2:
build:
context: ./apache
dockerfile: dockerfile_apache2
image: debian:latest
container_name: hsthttp2
extra_hosts:
- "somehost1:162.242.195.82"
- "somehost2:162.242.195.83"
- "somehost3:162.242.195.84"
- "somehost4:162.242.195.85"
web3:
build:
context: ./apache
dockerfile: dockerfile_apache2
image: debian:latest
container_name: hsthttp3
extra_hosts:
- "somehost1:162.242.195.82"
- "somehost2:162.242.195.83"
- "somehost3:162.242.195.84"
- "somehost4:162.242.195.85"
Yes, it's possible to use Extension fields to define reusable fragments since compose version 3.4:
For your situation, you can use next:
docker-compose.yaml:
version: '3.7'
x-extra_hosts:
&default-extra_hosts
- "somehost1:162.242.195.82"
- "somehost2:162.242.195.83"
- "somehost3:162.242.195.84"
- "somehost4:162.242.195.85"
services:
web:
image: debian:latest
container_name: hsthttp1
extra_hosts: *default-extra_hosts
web2:
image: debian:latest
container_name: hsthttp2
extra_hosts: *default-extra_hosts
web3:
image: debian:latest
container_name: hsthttp3
extra_hosts: *default-extra_hosts
Above, we define a global &default-extra_hosts which later in every service we can reference it with *default-extra_hosts.
You can use docker-compose config to quick check the effect as next:
shubuntu1#shubuntu1:~/try$ docker-compose config
services:
web:
container_name: hsthttp1
extra_hosts:
- somehost1:162.242.195.82
- somehost2:162.242.195.83
- somehost3:162.242.195.84
- somehost4:162.242.195.85
image: debian:latest
web2:
container_name: hsthttp2
extra_hosts:
- somehost1:162.242.195.82
- somehost2:162.242.195.83
- somehost3:162.242.195.84
- somehost4:162.242.195.85
image: debian:latest
web3:
container_name: hsthttp3
extra_hosts:
- somehost1:162.242.195.82
- somehost2:162.242.195.83
- somehost3:162.242.195.84
- somehost4:162.242.195.85
image: debian:latest
version: '3.7'

Resources