Search code examples
dockervue.jsdockerfilevue-cli-3docker-run

Docker Publish Option


I am attempting to get a Vue app running locally inside a Docker container and having an issue publishing to a specified port.

Here is my Dockerfile

FROM node:lts-alpine

RUN mkdir -p /app
COPY . /app
WORKDIR /app

RUN npm install
RUN npm run build

EXPOSE 3000

CMD ["npm", "start"]

In the root directory of my project I run

docker build --tag projectname .

This successfully creates an image which I should be able to run in a container.
However, whenever I run the following command I am unable to access the container from my browser at any port.

docker run -p 3000:3000 --name projectname projectname

The output shows some recommendations on splitting code to reduce size, but there are no errors, and it states that I should be able to access the app from http://localhost:8080, but that page provides a connection refused error.

I am under the impression that the publish option should listen on the exposed port 3000 and forward traffic to local port 3000.
However, this doesn't appear to be happening.

I am running Docker for Windows which might also be part of the problem.


Solution

  • Try running this command docker run -p 3000:8080 --name projectname projectname and then access the app at localhost:3000 on the docker host machine.

    If this works, then either update in your Dockerfile the EXPOSE 3000 into EXPOSE 8080, or start your http server on port 3000 instead of 8080 inside your app. This second step is optional, but it will help other folks understand that the containers launched from that image are supposed to be listening on the port that is mentioned in the Dockerfile.