docker-compose build with new tag - docker

I have a docker-compose which looks like:
version: '3.2'
services:
jobsaf-server:
build:
context: ./application
dockerfile: Dockerfile.production
container_name: jobsaf-server
env_file:
- ./application/.env
tty: true
depends_on:
- "redis"
- "mongo"
links:
- mongo
- redis
volumes:
- ./application/server:/var/www/app/jobsaf-website/server
- ./application/public/assets:/var/www/app/jobsaf-website/public/assets
- ./application/uploads:/var/www/app/jobsaf-website/uploads
- ./application/sitemaps:/var/www/app/jobsaf-website/sitemaps
- ./application/rss:/var/www/app/jobsaf-website/rss
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"
nginx:
image: nginx:stable
tty: true
env_file:
- ./.env
environment:
- NGINX_HOST=${APP_HOST}
- NGINX_PORT=${APP_PORT}
- PUID=1001
- PGID=1001
- TZ=Asia/Kabul
links:
- jobsaf-server
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./nginx/ssl/star_jobs_af.pem:/etc/ssl/star_jobs_af.pem
- ./nginx/ssl/jobs.af.key:/etc/ssl/jobs.af.key
- ./nginx/ssl/star_jobs_af.crt:/etc/ssl/star_jobs_af.crt
ports:
- "80:80"
- "443:443"
mongo:
image: mongo:latest
container_name: mongo
tty: true
env_file:
- ./.env
volumes:
- "db-data:/data/db"
environment:
- MONGO_INITDB_ROOT_USERNAME=${DB_USER}
- MONGO_INITDB_ROOT_PASSWORD=${DB_PASS}
- MONGO_INITDB_DATABASE=admin
ports:
- "0.0.0.0:27017:27017"
redis:
image: redis
container_name: redis
tty: true
volumes:
db-data:
# - /data/db
networks:
front-tier:
back-tier:
It build jobsaf-server:latest by default.
what I want is to keep the old tag and build the new one.
let say, while building the images I should pass something similar to this
docker-compose -f docker-compose.production --tag=1.0.1
the above command should build for me and image with tag jobsaf-server:1.0.1
Is it really possible to have such result?
Or is there any alternative solution for it
Thanks in advance.
Note: I want to keep the old image, in case if my new image has issue, then I can use the old image.

version: '3.2'
services:
jobsaf-server:
image: jobsaf-server:${TAG}
build:
context: ./application
dockerfile: Dockerfile.production
...
The best way to supply the tag is with a .env file like this:
TAG=1.0.1
Docker-compose will pick this up automatically.

From #Mihai suggestion following steps worked for me, incase if someone else needed.
version: '3.2'
services:
jobsaf-server:
image: jobsaf-server:${TAG}
build:
context: ./application
dockerfile: Dockerfile.production
To build:
Run TAG=1.0 docker-compose build it will create jobsaf-server:1.0
To Up:
Run TAG=1.0 docker-compose up -d
To down:
Run TAG=1.0 docker-compose down
Note: we can add TAG to .env file also by default.

Related

Docker-Compose build image and use its .env file which are stored in another directory

I have a docker-compose file which contains a bunch of services. To that docker-compose file, I want to add another service now. The other service files (including its .env) are stored in another folder. I tried to build it like I show you below, but it isnt working. Where do I go wrong?
The docker-compose.yml is contained in the directory nft-trading-service, the other dockerfile which I am trying to include in this docker-compose.yaml is in its own folder nft-asset-updater.
So the structure looks like this
root/nft-trading-server (holding docker-compose.yml)
root/nft-asset-updater (holding its own Dockerfile and .env)
version: "3"
services:
nftapi:
env_file:
- .env
build:
context: .
ports:
- '5000:5000'
depends_on:
- postgres
networks:
- postgres
extra_hosts:
- "host.docker.internal:host-gateway"
restart: always
asset_update_service:
env_file:
- .env
build:
context: ../nft-asset-updater
dockerfile: .
ports:
- '9000:9000'
depends_on:
- postgres
networks:
- postgres
extra_hosts:
- "host.docker.internal:host-gateway"
restart: always
postgres:
container_name: postgres
image: postgres:latest
ports:
- "5432:5432"
volumes:
- /data/postgres:/var/lib/postgresql/data
env_file:
- docker.env
networks:
- postgres
pgadmin:
links:
- postgres:postgres
container_name: pgadmin
image: dpage/pgadmin4
ports:
- "8080:80"
env_file:
- docker.env
networks:
- postgres
networks:
postgres:
driver: bridge

ERROR: In file './docker-compose.yml', service name True must be a quoted string, i.e. 'True'

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

Docker compose v3 - "Unsupported config option for volumes:"

I have a yml file with a configuration to run two containers. Here's the file:
web:
build: ./web
ports:
- "8000:8000"
restart: always
volumes:
- website:/www/
nginx:
build: ./nginx
ports:
- "80:80"
restart: always
links:
- web
volumes:
- website:/www/
volumes:
website:
When I run this I always get the following error:
The Compose file '.\docker-compose.yml' is invalid because:
Unsupported config option for volumes: 'website'
I have googled this and I think this is good as it is now. What is wrong with it?
i think you should add version and services in docker-compose file.
version: '3'
services:
web:
build: ./web
ports:
- "8000:8000"
restart: always
volumes:
- website:/www/
nginx:
build: ./nginx
ports:
- "80:80"
restart: always
links:
- web
volumes:
- website:/www/
volumes:
website:
reference :
docker compose file
getting start with docker-compose

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.

How I can group containers in docker-compose?

I'm using this docker-compose.yml.
And I wanna make simpler and inherrit configuration, if its possible.
version: '2'
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
web_one:
container_name: "web_one"
build:
context: ./
dockerfile: web.docker
volumes:
- ./../one:/var/www
environment:
- VIRTUAL_HOST=whoami_one.local
links:
- app_one
app_one:
container_name: "app_one"
build:
context: ./
dockerfile: app.docker
volumes:
- ./../one:/var/www
links:
- db
web_two:
container_name: "web_two"
build:
context: ./
dockerfile: web.docker
volumes:
- ./../two:/var/www
environment:
- VIRTUAL_HOST=whoami_two.local
links:
- app_two
app_two:
container_name: "app_two"
build:
context: ./
dockerfile: app.docker
volumes:
- ./../two:/var/www
links:
- db
I have 15 sites with same configuration.
Can I make config simpler? Like this:
version: '2'
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
one:
extends:
file: common-services.yml
volumes:
- ./../one:/var/www
environment:
- VIRTUAL_HOST=whoami_one.local
two:
extends:
file: common-services.yml
volumes:
- ./../two:/var/www
environment:
- VIRTUAL_HOST=whoami_two.local
Or better?
Thank you!
UPDATE 31 Aug 2021 In the latest docker compose there's support for profiles https://docs.docker.com/compose/profiles/ so this problem would be perfectly solved by that new feature.
Another way is to create no-op services that depend on other services.
For example, in the following docker-compose.yml I have two namespaces, dev for services needed when developing the app, and metrics for services related to visualizing app metrics (since I'm not interested instarting those when developing).
version: "3"
services:
dev:
image: tianon/true
depends_on: ["postgres", "keycloak"]
metrics:
image: monroe/noop
depends_on: ["grafana"]
postgres: ...
keycloak: ...
grafana: ...

Resources