Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Docker – Can't connect to my VueJS project

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

# 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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading