Search code examples
node.jsdockeramazon-elastic-beanstalkebcli

Unable to run docker container via ebcli on local machine


There seems to be some issue with how ebcli emits the docker run command.

Following is the command I am running on a MacOS machine

eb local run --port 3001

While eb is able to successfully build the docker image, it throws the error below when it tries to run the same.

docker: invalid publish opts format (should be name=value but got '3001:${PORT}').

Following is how my Dockerfile looks like

# Check out https://hub.docker.com/_/node to select a new base image
FROM node:10-slim

# Set to a non-root built-in user `node`
USER node

# Create app directory (with user `node`)
RUN mkdir -p /home/node/app

WORKDIR /home/node/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY --chown=node package*.json ./

RUN npm install

# Bundle app source code
COPY --chown=node . .

RUN npm run build

# Bind to all network interfaces so that it can be mapped to the host OS
ENV HOST=0.0.0.0 PORT=3000

EXPOSE ${PORT}

CMD [ "node", "." ]

Solution

  • This is a limitation of ebcli. The reason this is happening is that ebcli parses your dockerfile to retrieve the exposed port. Because ebcli reads your EXPOSE instruction as a literal string, when you are referencing an environment variable in your EXPOSE instruction ebcli attempts to pass that string to the port option as -p 3001:${PORT}.

    To resolve this you will need to modify your EXPOSE instruction to explicitly expose the value 3000.

    example:

    EXPOSE 3000
    

    There are enhancements that can be made to improve this experience. Feel free to report this on the ebcli github repository.