Home >Web Front-end >Front-end Q&A >How to use docker to deploy react projects

How to use docker to deploy react projects

藏色散人
藏色散人Original
2022-12-28 09:59:012977browse

How to use docker to deploy react projects: 1. Pull the nginx image through "docker pull nginx"; 2. Check whether the pull is successful; 3. Use "docker run --name reactweb -p 8088:80 -d nginx" to create and start an nginx container; 4. Modify the nginx information and copy the local files to the docker image.

How to use docker to deploy react projects

The operating environment of this tutorial: Windows 10 system, react18.0.0 version, Dell G3 computer.

How to use docker to deploy react projects?

Teach you step by step how to deploy a react project in docker (deploy nginx in docker)

1. Pull the nginx image

docker pull nginx

2. Check whether the pull is successful

docker images

3. Create and start an nginx container

docker run --name reactweb -p 8088:80 -d nginx

-name: Name the newly created container, here is: reactweb

-p: Port mapping, put the host The 8088 port is mapped to the 80 port of the container, that is, the last access to localhost:8088

-d: After successful startup, output the complete container ID

nginx: Mirror name

At this time, you can test whether nginx appears when accessing localhost:8088

3.1. Enter the MySQL container

docker exec -it reactweb sh

4. You may need to modify the nginx information and use vim

apt-get update
apt-get install vim

5. Copy local files to the docker image

docker cp local address container id:nginx mapping address

local address:/Application/code/build

container id:docker ps -a To view the

nginx mapping address, you can enter the container and then view the default.conf in /etc/nginx/conf.d. The default is usr/share/nginx/html

6. If You need to modify the nginx conf

cd /etc/nginx/conf.d
vim default.conf
// 编辑完保存后 重启nginx
nginx -s reload

You can access it locally

Recommended learning: "react video tutorial"

The above is the detailed content of How to use docker to deploy react projects. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn