How to Run a Docker Container in Aws Elastic Beanstalk with Non-Default Run Parameters

Deploying Docker to AWS Elastic Beanstalk: failed to execute command 'docker pull maven'

I figured it out so I will leave an answer for future readers. Turns out AWS doesn't allow you to use the AS keyword in Docker. So I changed the file from:

# Build stage 
#
FROM maven:3.8.1-jdk-8 AS build
ADD src /tmp/src
ADD pom.xml /tmp/pom.xml
RUN mvn -f /tmp/pom.xml clean package

#
# Package stage
#
FROM openjdk:8
COPY --from=build /tmp/target/my-project-host-0.0.1-SNAPSHOT.jar /usr/local/lib/my-project.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/lib/my-project.jar"]

To this:

# Build stage 
#
FROM maven:3.8.1-jdk-8
ADD src /tmp/src
ADD pom.xml /tmp/pom.xml
RUN mvn -f /tmp/pom.xml clean package

#
# Package stage
#
FROM openjdk:8
COPY --from=0 /tmp/target/my-project-host-0.0.1-SNAPSHOT.jar /usr/local/lib/my-project.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/lib/my-project.jar"]

AWS Elastic Beanstalk - how to stop previous docker before starting new one

immutable updates can be the way to go for you, it basically recreates the EC2 instances completely on every deploy

  1. Open the Elastic Beanstalk console.
  2. Navigate to the management page for your environment.
  3. Choose Configuration.
  4. In the Rolling updates and deployments configuration category,
    choose Modify.
  5. Select immutable on deploy policy
  6. Apply

you can check more on how it works here

In elastic beanstalk, how do I run a command before the container is launched?

Either you replace the CMD/ENTRYPOINT with a script where you run that inside the running docker container (runs each time you start the docker container), or you add this to .ebextensions/00-my-tasks.config:

container_commands:
00-my-task:
command: rake db:migrate

Then it runs in the elastic-beanstalk container/virtual machine, but outside of docker container.



Related Topics



Leave a reply



Submit