I have a dockerized app that has 3 levels, a frontend with React, a backend with Django/Python, and a database with postgres.
So, in the root directory there’s a docker-compose.yml file instead of a simple Dockerfile, the frontend service has its own Dockerfile, as well as the backend service, and the database level doesn’t have a Dockerfile, but it is working with the postgres image downloaded from Docker.
I created a fly.toml file in the root directory made from my docker-compose.yml file, this is the fly.toml file:
(the images there are the real images produced from doing docker-compose up --build)
app = "my app name"
org = "my organization"
[[services]]
internal_port = 5432
protocol = "tcp"
[services.concurrency]
hard_limit = 1
[services.env]
POSTGRES_USER = "my user"
POSTGRES_PASSWORD = "my password"
POSTGRES_DB = "menu_db"
[[services]]
internal_port = 8000
protocol = "tcp"
[services.concurrency]
hard_limit = 2
[[services.ports]]
handlers = ["http"]
port = "8000"
# Add any environment variables needed for your API service
image = "docker-whole-menu-api:latest"
[[services]]
internal_port = 3000
protocol = "tcp"
[services.concurrency]
hard_limit = 1
[[services.ports]]
handlers = ["http"]
port = "3000"
# Add any environment variables needed for your web service
image = "docker-whole-menu-web:latest"
My docker-compose.yml file is:
version: '3.8'
services:
db:
image: postgres
container_name: docker-whole-menu-db
environment:
POSTGRES_USER: <my user>
POSTGRES_PASSWORD: <my password>
POSTGRES_DB: menu_db
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
- ./initdb.d:/docker-entrypoint-initdb.d
networks:
- my_network
api:
build:
context: ./api
dockerfile: Dockerfile
container_name: docker-whole-menu-api
command: sh -c "./wait-for-it.sh db:5432 -- python backend/manage.py migrate && python backend/manage.py runserver 0.0.0.0:8000"
ports:
- "8000:8000"
depends_on:
- db
volumes:
- ./api/backend:/app/api/backend
networks:
- my_network
web:
build:
context: ./web
dockerfile: Dockerfile
container_name: docker-whole-menu-web
command: npm run serve
ports:
- "3000:3000"
networks:
- my_network
networks:
my_network:
volumes:
pgdata:
When I try to deploy, fly deploy asks for a Dockerfile in the root, but there’s a docker-compose file, what do you suggest me to do?
This is what I get:
fly deploy
==> Verifying app config
Validating C:\WebDev\menu-app-project\docker-whole-menu\fly.toml
Platform: machines
✓ Configuration is valid
--> Verified app config
==> Building image
Remote builder fly-builder-muddy-mountain-4150 ready
Error: failed to fetch an image or build from source: app does not have a Dockerfile or buildpacks configured. See https://fly.io/docs/reference/configuration/#the-build-section