Implementation of Docker deployment of Nuxt.js project

Implementation of Docker deployment of Nuxt.js project

Docker official documentation: https://docs.docker.com/

Docker is an open source application container engine that allows developers to package their applications and dependencies into a portable image and then publish it to any popular Linux or Windows machine, and can also achieve virtualization. Containers use a complete sandbox mechanism and do not have any interfaces with each other.

Deploy nuxt.js project using docker

1. Build a node image

FROM node:alpine

Why use the alpine version?

Compared to other Docker images, its capacity is very small, only about 5 MB (compared to nearly 200 MB for Ubuntu series images), and it has a very friendly package management mechanism. The official image comes from the docker-alpine project. Currently, Docker officially recommends using Alpine to replace Ubuntu as the base image environment. This has several benefits. These include faster image download speeds, improved image security, easier switching between hosts, and less disk space usage.

2. Set the project save directory

RUN mkdir -p /app/src

3. Copy the project code to the image

COPY ./src /app/src

4. Specify the directory where the command is executed

WORKDIR /app/src

5. Set up the host

ENV HOST 0.0.0.0

6. Execute project installation and compilation

RUN npm install RUN npm run build RUN npm cache clean --force

7. Set external access port

EXPOSE 3000

8. Execute the nuxt project run command

CMD ["npm", "start"]

Complete Dockerfile

FROM node:alpine

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

ENV HOST "0.0.0.0"

RUN sed -i "s/dl-cdn.alpinelinux.org/${ALPINE_REPOSITORIES}/g" /etc/apk/repositories

RUN apk add --no-cache make gcc g++ python

RUN npm install
RUN npm run build
RUN npm cache clean --force

RUN apk del make gcc g++ python

EXPOSE 3000
CMD ["npm", "start"]

When using sass or scss in a project, you need to rely on the python environment, so you need to install python. Of course, after compiling the relevant resources, you can delete the corresponding dependencies to reduce the image size.

Run Docker

1. Build an image

docker build -t nuxt-demo

2. Start the container

docker run -dt -p 3000:3000 nuxt-demo

3. Access

Open your browser and access 127.0.0.1:3000

1. You can use Docker Compose to orchestrate containers and quickly deploy multi-container applications.
2. You can use nginx to proxy the container to avoid directly accessing the container in the form of a port.

This is the end of this article about the implementation of Docker deployment of Nuxt.js project. For more relevant Docker deployment of Nuxt.js content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • nuxt.js adds environment variables to distinguish project packaging environment operations
  • Configuration operations of axios and proxy in nuxt.js server-side rendering
  • Differences between Nuxt.js nuxt-link and router-link
  • Nuxt.js routing jump operation (page jump nuxt-link)
  • nuxt.js implements routing authentication in middleware
  • Nuxt.js static resources and packaging operations
  • Add error prompt page operation when writing nuxt.js project
  • Creating a nuxt.js project flow chart
  • nuxt.js multiple environment variable configuration

<<:  Implementation of mysql decimal data type conversion

>>:  W3C Tutorial (4): W3C XHTML Activities

Recommend

Web Design Tutorial (1): Steps and Overall Layout

<br /> Note: All texts, except those indicat...

A brief analysis of the difference between static and self in PHP classes

Use self:: or __CLASS__ to get a static reference...

Summary of 10 amazing tricks of Element-UI

Table of contents el-scrollbar scroll bar el-uplo...

Detailed steps for smooth transition from MySQL to MariaDB

1. Introduction to MariaDB and MySQL 1. Introduct...

The connection between JavaScript constructors and prototypes

Table of contents 1. Constructors and prototypes ...

How to call the interrupted system in Linux

Preface Slow system calls refer to system calls t...

Nginx defines domain name access method

I'm building Nginx recently, but I can't ...

Teach you how to write maintainable JS code

Table of contents What is maintainable code? Code...

Zabbix configuration DingTalk alarm function implementation code

need Configuring DingTalk alarms in Zabbix is ​​s...

How to make a centos base image

Preface Now the operating system used by my compa...

Django2.* + Mysql5.7 development environment integration tutorial diagram

environment: MAC_OS 10.12 Python 3.6 mysql 5.7.25...

Pagination Examples and Good Practices

<br />Structure and hierarchy reduce complex...