Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Elastic Beanstalk Docker Does not support Multi-Stage Build

I am struggling to get my build deploying to AWS on Docker. I have no idea where the solution lays as this is my first time with Docker. I have got it all working fine locally, but when I deploy I get the following error in Elastic Beanstalk:

2020/04/30 05:35:02.330900 [ERROR] An error occurred during execution of command [app-deploy] - [Docker Specific Build Application]. Stop running the command. Error: failed to pull docker image: Command /bin/sh -c docker pull node:13.3.0 AS compile-image failed with error exit status 1. Stderr:"docker pull" requires exactly 1 argument.
See 'docker pull --help'.

This is what my Docker file looks like:

FROM node:13-alpine as builder

WORKDIR /opt/ng
COPY package.json package-lock.json ./
RUN npm install

ENV PATH="./node_modules/.bin:$PATH"

COPY . ./
RUN ng build --prod

FROM nginx:1.18-alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /opt/ng/dist/angular-universal-app/browser /usr/share/nginx/html

Can someone please point me in the right direction? Or is this method of Multi-Stage builds not supported by Elastic Beanstalk's Docker version?

like image 723
Simon Sebastian Vollmer Avatar asked Apr 30 '20 07:04

Simon Sebastian Vollmer


People also ask

Does Elastic Beanstalk support Docker?

Elastic Beanstalk supports the deployment of web applications from Docker containers. With Docker containers, you can define your own runtime environment.

What is Docker multistage build?

A multistage Docker build is a process to create a Docker image through a series of steps. Each stage accomplishes a task -- such as to load or remove build tools -- specific to the base Docker image, as part of the compilation process.

How do you use Elastic Beanstalk with Docker?

Deploy to the Cloud Using the Elastic Beanstalk Console Choose “AWS Cloud9” and “Go To Your Dashboard.” Choose “Services” and “Elastic Beanstalk.” At the top right, choose “Create Application.” Paste flask-app for the “Application Name.” For “Platform,” choose “Docker.” Leave the Docker settings as is.

Why use multi stage builds Docker?

With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don't want in the final image.


2 Answers

I had the same problem. Actually I check the following rows in my log file:

2020/05/26 17:26:30.327310 [INFO] Running command /bin/sh -c docker pull node:alpine as builder
2020/05/26 17:26:30.369280 [ERROR] "docker pull" requires exactly 1 argument.

As you can seen, it tries to make a 'docker pull' with 3 arguments:

  1. node:alpine
  2. as
  3. builder

and of course, that is not possible because it requires only 1 argument. Thus, apparently AWS Elastic Beanstalk doesn't support stage naming. For this reason I solved using an Unnamed builder:

FROM node:13-alpine

and in the end:

COPY --from=0 /opt/ng/dist/angular-universal-app/browser /usr/share/nginx/html

Final Dockerfile:

FROM node:13-alpine

WORKDIR /opt/ng
COPY package.json package-lock.json ./
RUN npm install

ENV PATH="./node_modules/.bin:$PATH"

COPY . ./
RUN ng build --prod

FROM nginx:1.18-alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=0 /opt/ng/dist/angular-universal-app/browser /usr/share/nginx/html

For me it works using that solution. If someone has any problem, please share the last-100-lines log

like image 133
Alfonso Silvestri Avatar answered Oct 12 '22 12:10

Alfonso Silvestri


I have seen this error when using a solution stack that uses 'Amazon Linux 2'. These platforms are new and have some ongoing issues.

Amazon Linux 2 support for AWS Elastic Beanstalk is in beta release and is subject to change.

  • https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-beta.html

Please use a solution stack that has 'Amazon Linux' in the name. You should not face the issue there.

like image 36
shariqmaws Avatar answered Oct 12 '22 12:10

shariqmaws