Home > other >  Docker - Can't connect to my VueJS project
Docker - Can't connect to my VueJS project

Time:04-22


I'm trying to run my docker image with the following command but i cannot connect to my web VueJS project :
docker run -it -p 8080:8080 --rm dependency_check_front

In my debug, I have :

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/04/21 10:26:55 [notice] 1#1: using the "epoll" event method
2022/04/21 10:26:55 [notice] 1#1: nginx/1.20.2
2022/04/21 10:26:55 [notice] 1#1: built by gcc 10.3.1 20210424 (Alpine 10.3.1_git20210424) 
2022/04/21 10:26:55 [notice] 1#1: OS: Linux 5.10.102.1-microsoft-standard-WSL2
2022/04/21 10:26:55 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2022/04/21 10:26:55 [notice] 1#1: start worker processes
2022/04/21 10:26:55 [notice] 1#1: start worker process 33
2022/04/21 10:26:55 [notice] 1#1: start worker process 34
2022/04/21 10:26:55 [notice] 1#1: start worker process 35
2022/04/21 10:26:55 [notice] 1#1: start worker process 36

My dockerfile of the VueJS project :

# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]

When i try to connect on my website, i have this error : enter image description here

CodePudding user response:

The EXPOSE statement doesn't really do anything. It's mostly a bit of documentation on what port your container listens on. And in your case it's not correct, since Nginx listens on port 80 by default.

When you run the container, you should map port 80 to the port you want to use on the host. I.e.

docker run -it -p 8080:80 --rm dependency_check_front

Now you should be able to reach your app at http://localhost:8080/

You should remove the EXPOSE statement in your Dockerfile, since it can confuse anyone looking at your Dockerfile later.

If you really want Nginx to listen on port 8080, you have to configure Nginx to do that, but IMO it's not worth it. Just have it listen on port 80.

  • Related