https://github.com/hodanov/react-django-postgres-sample-app I want to deploy the DB, API, and FRONT containers in the above repository to AWS ECS so that they can be operated.
Therefore, in order to operate the containers separately, the docker-compose.yaml file was divided into containers.
I pushed the container to ECR and operated it with ECS, but it stopped by all means. Where should I review it?
I spent some time on this. Where do I start :)
First and foremost the compose file has bind mounts that can't work when you deploy to ECS/Fargate (because the local files mounted do not exist on the remote end). So these are the 3 things that needs to be done:
rest_api
and the web_front
services.ADD ./code/django_rest_api/ /code
in DockerfilePython
and append ADD ./code/django_web_front/ /code
in DockerfileNode
. This will basically simulate the bind mount and will include the content of the folder right in the image(s).image
field to the three services. That will allow you to docker compose build
and docker compose push` so that the images are available to be deployed in the cloud.This is my resulting compose file (you need to change your images repos):
version: "3"
services:
db:
container_name: django_db
image: mreferre/django_db:latest
build:
context: .
dockerfile: DockerfilePostgres
volumes:
- django_data_volume:/var/lib/postgresql/data
rest_api:
container_name: django_rest_api
image: mreferre/django_rest_api:latest
build:
context: .
dockerfile: DockerfilePython
command: ./run-migrate-and-server.sh
# volumes:
# - ./code/django_rest_api:/code
tty: true
ports:
- 8000:8000
depends_on:
- db
web_front:
container_name: django_web_front
image: mreferre/django_web_front:latest
build:
context: .
dockerfile: DockerfileNode
command: ./npm-install-and-start.sh
# volumes:
# - ./code/django_web_front:/code
tty: true
ports:
- 3000:3000
depends_on:
- rest_api
volumes:
django_data_volume:
This will deploy just fine with docker compose up
in the ECS context and the API server will work. HOWEVER, the React front end will not work because the App.js
code points to localhost:
const constants = {
"url": "http://localhost:8000/api/profile/?format=json"
}
I don't know what the React equivalent is but in Angular you need to point to something along the lines of window.location.href
to tell the app to point to the same endpoint your browser connected to.
If you fix this problem then it should just work(tm).