version: '2'
services:
service1:
build:
image: company/service1:v1
context: .
- dockerfile: Dockerfile-service1
service2:
build: .
image: company/service2:v1
links:
- service1
I have two Dockerfiles, one is called Dockerfile and one is called Dockerfile-service1 both in the same directory (/opt) as the docker-compose.yml.
I need to build both images and start the containers and link them. In order for me to do that now, I move the Dockerfile-service1 into another directory and rename it to Dockerfile and then run the build command like this: docker build -t company/service1:v1 .
Then I go to the /opt directory again and build the service2 image and start both containers: docker build . --no-cache -t company/service2:v1 && docker-compose up -d
There must be a better way so I can run one command that does both, I just don't know how.
How do I solve this problem?