awsdocs / elastic-beanstalk-samples

This repository contains code and configuration samples (e.g. .ebextensions) for AWS Elastic Beanstalk.
Apache License 2.0
1.22k stars 889 forks source link

Change docker-compose build and run command #166

Closed ngohuytrieu closed 1 year ago

ngohuytrieu commented 1 year ago

Hi, I am using AWS ELB (docker) for my production website and I am running into this stuck for days.

I need to custom a docker-compose build and run command into something like

docker-compose build --build-arg TARGET_ENV='dev'
docker-compose up -d

but couldn't get it to work. Please help

Here are solutions that I tried:

  1. Configuration file with container_command .ebextensions/myapp.config
container_commands:
  01_build:
    command: "docker-compose build --build-arg TARGET_ENV='dev'"
  02_start:
    command: "docker-compose up -d"
  1. Predeploy script
    • .elasticbeanstalk/config.yml
      option_settings:
      aws:elasticbeanstalk:container:predeploy:
      - source: predeploy.sh
      destination: /opt/elasticbeanstalk/hooks/appdeploy/pre
      runas: root
    • .ebextensions/predeploy.sh
#!/bin/bash

# if a command fails, the script will stop running and exit immediately
set -e

# Set execute permission on the script
chmod +x predeploy.sh

# Build the Docker image
docker-compose build --build-arg TARGET_ENV="dev"

# Start the containers
docker-compose up -d
ngohuytrieu commented 1 year ago

So turns out, AWS ELB (docker) doesn't support customizing a run and build command on the Managed platform type You have to change to the Custom platform type in order to customize a run and build command.