Search code examples
reactjsamazon-web-servicesdockeramazon-elastic-beanstalktravis-ci

Docker container works locally but not when uploaded to elasticbeanstalk


My docker container works locally, I'm trying to deploy it on elastic beanstalk using travis. My travis build is successful. The docker container has been tested locally and it works. On AWS Elastic Beanstalk I get a "Not a file/Directory error" for my build directory.

Dockerfile

FROM node:alpine as builder

WORKDIR '/app'

COPY package.json .
RUN npm install

COPY . .

CMD ["npm", "run", "build"]

#Run Phase
FROM nginx 
EXPOSE 80
COPY --from=builder /app/build /usr/share/nginx/html

Dockerfile.dev

FROM node:alpine

WORKDIR '/app'

COPY package.json .
RUN npm install 

COPY . .

CMD ["npm", "run", "start"]

travis.yml

sudo: required
services:
    - docker

before_install:
    - docker build -t *******/docker -f Dockerfile.dev .
script:
    - docker run -e CI=true *******/docker npm run test -- --coverage

deploy:
    provider: elasticbeanstalk
    region: "ap-south-1"
    app: "docker"
    env: "Docker-env-2"
    bucket_name: "***********************"
    bucket_path: "docker"
    on:
        branch: master
    access_key_id: $AWS_ACCESS_KEY
    secret_access_key: $AWS_SECRET_KEY

Following are the logs -

Travis output

Elastic Beanstalk output

Any help would be appreciated, thanks!

To run it locally, I run the following commands-

1) docker build -t *******/docker .
2) docker run -it <port>:80 <container_id>

It works as expected and I can reach the server on localhost:. I've put the same commands on the travis.yml file as well.

There are two dockerfiles because I would only be needing the "build" directory in the production container and I can ignore the rest of the directories to save space.


Solution

  • I realized that the build directory was listed in the .gitignore file, thereby preventing travis-ci from accessing it as it isn't in the repo. Once I removed it and re-deployed it, worked perfectly.