I have 2 services which use the same image:
, what can i do, to force docker-compose to generate 2 seperate containers?
Thanks!
EDIT:
Full docker-compose:
version: "3.5"
services:
database:
container_name: proj-database
env_file: ../orm/.env.${PROJ_ENV}
image: postgres
restart: always
ports:
- 5432:5432
networks:
- proj
api:
image: golang:1.17
container_name: proj-api
env_file: ../cryptoModuleAPI/.env.${PROJ_ENV}
restart: always
build: ../cryptoModuleAPI/
links:
- database:database
ports:
- 8080:8080
volumes:
- ../cryptoModuleAPI:/proj/api
- ../orm:/proj/orm
networks:
- proj
admin:
image: golang:1.17
container_name: proj-admin
env_file: ../admin/.env.${PROJ_ENV}
restart: always
build: ../admin/
links:
- database:database
ports:
- 8081:8081
volumes:
- ../admin:/proj/admin
- ../orm:/proj/orm
networks:
- proj
networks:
proj:
external:
name: proj
I just run with docker-compose up
CodePudding user response:
You misunderstand how the build and the image directives work when used together.
Paraphrasing from the docs,
https://docs.docker.com/compose/compose-file/compose-file-v3/#build
the behavior when using both is like so:
If you specify image as well as build, then Compose names the built image with the value of the image directive.
So compose is going to build two images, both named the same thing. Only one will survive. I'm surprised your app runs at all!
Provide a different name for the mage directive of each service, or leave it out entirely.