AWS Elastic Beanstalk Docker Does not support Multi-Stage Build
Asked Answered
H

3

23

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?

Histogen answered 30/4, 2020 at 7:56 Comment(0)
I
34

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

Industrial answered 26/5, 2020 at 21:35 Comment(0)
M
6

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.

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

Martinemartineau answered 30/4, 2020 at 17:18 Comment(1)
If you want/need to use Linux 2, Alfonso's answer below works.Pathology
T
-1

Had the same problem with the added "as builder." I got it to work with as builder with the following version of AWS Linux: 64bit Amazon Linux 2/3.6.5. I have version 24.0.7 of Docker.

Tammietammuz answered 19/1 at 17:29 Comment(5)
Les, please don't add thanks as answers. They don't actually provide an answer to the question, and can be perceived as noise by its future visitors. Once you earn enough reputation, you will gain privileges to upvote answers you like. This way future visitors of the question will see a higher vote count on that answer, and the answerer will also be rewarded with reputation points. See Why is voting important.Ligetti
how is this not an answer? it originally had a "thanks" in it, but the answer it seemed to thank is saying to not use "Amazon Linux 2".Slighting
I'm confused; saying what worked for me is not an answer? <politeness and cordiality not required here, huh?>Tammietammuz
I suggest to provide more context, since it seems you are referencing another answer that suggested that stage naming ("as builder") in the Dockerfile does not work with this specific setup. Your answer should be understandable on its own.Cystitis
Gotcha, probably would have been more appropriate as a reply to bottom of the post to which I was referring, rather than an entirely new answer.Tammietammuz

© 2022 - 2024 — McMap. All rights reserved.