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

Specific use of stacking context in CSS

Preface Under the influence of some CSS interacti...

Detailed explanation of the difference between in and exists in MySQL

1. Prepare in Advance For your convenience, I cre...

Overview of time configuration under Linux system

1. Time types are divided into: 1. Network time (...

Use momentJs to make a countdown component (example code)

Today I'd like to introduce a countdown made ...

Detailed explanation of the background-position percentage principle

When I was helping someone adjust the code today,...

MySQL and sqlyog installation tutorial with pictures and text

1. MySQL 1.1 MySQL installation mysql-5.5.27-winx...

MySQL 8.0.22 winx64 installation and configuration method graphic tutorial

The database installation tutorial of MySQL-8.0.2...

Implementation of dynamic rem for mobile layout

Dynamic rem 1. First, let’s introduce the current...

An article to understand the execution process of MySQL query statements

Preface We need to retrieve certain data that mee...

JavaScript two pictures to understand the prototype chain

Table of contents 1. Prototype Relationship 2. Pr...

How is a SQL statement executed in MySQL?

Table of contents 1. Analysis of MySQL architectu...

Teach you step by step to configure MySQL remote access

Preface When using the MySQL database, sometimes ...

Nginx tp3.2.3 404 problem solution

Recently I changed Apache to nginx. When I moved ...