Reputation: 101
I have a simple vue + django project and I want to be able to containerize this project with docker but I've run into some issues. I have dockerfiles and docker compose files in each subfolder - frontend and backend - and if I cd into either I can successfully start each individual project using docker compose with no problems.
However, I want to be able to run one single docker compose command that can create both images simultaneously. I currently have a docker compose file in the root directory of the project and I am including the compose files and referencing them in the services. It works fine with just the vue service but gives me an error when I include the django services. Error code is this:
failed to solve: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount2369903057/Dockerfile: no such file or directory
The django project was created using cookiecutter so it has everything I need in the project. Here is a simple version of my file structure:
- api
- compose
- Dockerfile
- docker-compose.yml
- frontend
- Dockerfile
- docker-compose.yml
- docker-compose.yml
Here is my backend compose file:
volumes:
api_local_postgres_data: {}
api_local_postgres_data_backups: {}
services:
django:
build:
context: .
dockerfile: ./compose/local/django/Dockerfile
image: api_local_django
container_name: api_local_django
depends_on:
- postgres
volumes:
- .:/app:z
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.postgres
ports:
- '8000:8000'
command: /start
postgres:
build:
context: .
dockerfile: ./compose/production/postgres/Dockerfile
image: api_production_postgres
container_name: api_local_postgres
volumes:
- api_local_postgres_data:/var/lib/postgresql/data
- api_local_postgres_data_backups:/backups
env_file:
- ./.envs/.local/.postgres
docs:
image: api_local_docs
container_name: api_local_docs
build:
context: .
dockerfile: ./compose/local/docs/Dockerfile
env_file:
- ./.envs/.local/.django
volumes:
- ./docs:/docs:z
- ./config:/app/config:z
- ./api:/app/api:z
ports:
- '9000:9000'
command: /start-docs
Here's the root compose:
include:
- ./frontend/docker-compose.yml
- ./api/docker-compose.yml
services:
frontend_vue:
build: ./frontend
depends_on:
- vue-ui
backend_django:
build: ./api
depends_on:
- django
backend_postgres:
build: ./api
depends_on:
- postgres
backend_docs:
build: ./api
depends_on:
- docs
Upvotes: 2
Views: 6268
Reputation: 284
You don't need to redeclare the services in in the root docker-compose.yml
file.
For instance, when you include the api/docker-compose.yml
in your root docker-compose.yml
file, all the services defined in the api/docker-compose.yml
file are loaded into the root compose application model. Therefore, the services are already available in the root compose application, and you don't need to declare it again in the root docker-compose.yml
file.
So, the docker-compose.yml
files would look like:
root docker-compose.yml
:
include:
- ./frontend/docker-compose.yml
- ./api/docker-compose.yml
api/docker-compose.yml
:
version: '3'
services:
...
Upvotes: 2