Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS copilot with Django never finishes deploying

I've followed the this short guide to create a django app with docker https://docs.docker.com/compose/django/

and then following copilot instructional to push up the container to ECS: https://aws.amazon.com/blogs/containers/introducing-aws-copilot/

I've also used this sample to test everything -- which works out fine: https://github.com/aws-samples/aws-copilot-sample-service The deploy completes and outputs and URL endpoint.

In my case, the everything is successfully built, but once the test environment is being deployed it just continuously builds at this:

72ff4719 size: 3055
⠏ Deploying load-bal:7158348 to test.

and never finishes. I've even downsized my requirements.txt to a bare minimum.

My Dockerfile

FROM python:3.7.4
ENV PYTHONUNBUFFERED=1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
EXPOSE 80
COPY . /code/

docker-compose.yml

version: "3.8"
   
services:
  db:
    image: postgres
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

requirements.txt

Django==3.0.8
djangorestframework==3.11.0
gunicorn==20.0.4
pipenv==2020.6.2
psycopg2-binary==2.8.5
virtualenv==16.7.6

Instructions I follow:

sudo docker-compose run web django-admin startproject composeexample .

Successfully creates the Django App

copilot init

Setup naming for app and load balancer

Choose to create test environment

Everything builds successfully and then just sits here. I've tried a number of variations, but the only one that works is just doing the copilot instructional without django involved.

6f3494a64128: Pushed 
cfe650cc4def: Pushed 
a477d6671cc7: Pushed 
90df760355a7: Pushed 
574ea6c52bdd: Pushed 
d1573fad78d1: Pushed 
14c1ff636882: Pushed 
48ebd1638acd: Pushed 
31f78d833a92: Pushed 
2ea751c0f96c: Pushed 
7a435d49206f: Pushed 
9674e3075904: Pushed 
831b66a484dc: Pushed 
ini: digest: sha256:b7460876bc84b1a26e7513fa6d17b5bffd5560ae958a933984376ed2c9fe53f3 size: 3052
⠏ Deploying aiinterview-lb:ini to test. 
like image 842
user291813 Avatar asked Nov 29 '25 08:11

user291813


1 Answers

tl;dr the Dockerfile that's being used by this tutorial is incomplete for Copilot's purposes. It needs an extra line containing

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

and the EXPOSE directive should be updated to 8000. Because Copilot doesn't recognize Docker Compose syntax and there's no command or entrypoint specified in the Dockerfile, the image will never start with Copilot's configuration settings.

Details

AWS Copilot is designed around "services" consisting of an image, possible sidecars, and additional storage resources. That means that its basic unit of config is the Docker image and the service manifest. It doesn't natively read Docker Compose syntax, so all the config that Copilot knows about is that which is specified in the Dockerfile or image and each service's manifest.yml and addons directory.

In this example, designed for use with Docker Compose, the Dockerfile doesn't have any kind of CMD or ENTRYPOINT directive, so the built image which gets pushed to Amazon ECR by Copilot won't ever start. The tutorial specifies the image's command (python manage.py runserver 0.0.0.0:8000) as an override in docker-compose.yml, so you'll want to update your Dockerfile to the following:

FROM python:3.7.4
ENV PYTHONUNBUFFERED=1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
EXPOSE 8000
COPY . /code/
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

Note here that I've changed the EXPOSE directive to 8000 to match the command from docker-compose.yml and added the command specified in the web section to the Dockerfile as a CMD directive.

You'll also want to run

copilot init --image postgres --name db --port 5432 --type "Backend Service" --deploy

This will create the db service specified in your docker-compose.yml. You may need to run this first so that your web container doesn't fail to start while searching for credentials.

Some other notes:

  • You can specify your database credentials by adding variables and secrets in the manifest file for db which is created in your workspace at ./copilot/db/manifest.yml. For more on how to add a secret to SSM and make it accessible to your Copilot services, check out our documentation
variables: 
  POSTGRES_DB: postgres
  POSTGRES_USER: postgres

secrets:
  POSTGRES_PASSWORD: POSTGRES_PASSWORD
  • Your database endpoint is accessible over service discovery at db.$COPILOT_SERVICE_DISCOVERY_ENDPOINT--you may need to update your service code which connects to the database to reflect this endpoint instead of localhost or 0.0.0.0.
like image 65
Austin Ely Avatar answered Dec 02 '25 01:12

Austin Ely



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!