The finished project needs to be packaged and put online to the cloud server, which needs to use docker container, Nginx reverse proxy and cloud server deployment, etc. Next, the author will make a record of the process of a project launch, which is convenient for future review at any time.

Manipulate the Docker image

1.Pull mirror using domestic mirror warehouse, fast//http://hub.daocloud.io/Docker pull image name2.View all local docker images3.Delete the identifier of all local docker RMI images4.Import and export a local image// Export the local imageDocker save -o File name Image ID// Import a local imageDocker load -i image file5.Docker tag Image ID New nameCopy the code

Container operation

1.Running container docker run | mirror mirror id name docker run - d - p hosting port: container port - name container name | mirror mirror id name//-d Back-end run container
//-p to map the current Linux port and container port
//--name Specifies the container name


2.Docker ps [-QA]//-a views all containers, including those that are not running
//-q Displays only the container identifier


3.Docker logs -f Container ID//-f can scroll to the last few lines of the log


4.Docker exec-it container id bash Docker exec-it container ID sh5.Delete the container. Stop the container before deleting it// Stop the specified containerDocker stop Container ID// Stop all containersDocker stop $(docker ps-QA) docker rm $(docker ps-QA)6.Start the container docker start container id | vessel name7.Changing the container name Docker commit Container ID New nameCopy the code

SSH Login Service

ssh ${user}@${ip}
// You will be prompted for your password
// The system prompts you to save the SSH information upon your first login. Enter yes

// Copy files from local to remote
scp -rp /path/filename username@remoteIP:/path
Copy the code

Deploy the project in Aliyun

1.Lvm2 install yum install Yum-utils device-mapper-Persistent-data lvm22.Yum -config-manager --add-repo//mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo


3.Docker ym install docker-ce docker-ce cli containerd. IO4.Start Docker and set it to boot automatically// Start docker service
systemctl start docker

// Start docker automatically
systemctl enable docker

/ / test
docker run hello-world


5.Modify the image source vi /etc/docker-daemon. json {"registry-mirrors": ["https://register.docker-cn.com/"]}/ / restart docker
systemctl daemon-reload
systemctl restart docker


6.Install MySQL docker pull daocloud. IO/library/MySQL:8.020.

/ / run MySQL
docker run -d -p 3306:3306--name mysql -e MYSQL_ROOT_PASSWORD=abc123456 Mirror ID7.Install redis docker pull daocloud. IO/library/redis:6.03.-alpine311.

/ / run redis
docker run -d -p 6379:6379--name er_redis Image ID -- requirePass abc1234568.Install the node docker pull daocloud. IO/library/node:12.18

// Start node containerDocker run-itd --name Node image ID// Enter the container to create the file
mkdir egg

// Copy files from local to remote
scp -rp egg.zip root@remoteIP:/path

unzip -u -d server egg.zip
docker bulid -t egg:1.0 ./server
docker run -d -p 7001:7001 --name egg1. 0Mirror id// Copy the local codeDocker cp dist nginx container id:/egg9.Install nginx docker pull daocloud. IO/library/nginx:1.13. 0-alpine

// Nginx configuration file
/etc/nginx/nginx.conf

// HTML directory in nginx
/usr/share/nginx/html

// Log file
/var/log/nginx/access.log

// Copy files from local to remote
scp -rp dist root@remoteIP:/root

// Copy files from the host to the containerDocker cp dist nginx/usr/share/nginx/html
Copy the code

Configure nginx

vi /etc/nginx/nginx.conf

// Add content
server {
    // Listen on the port
    listen 80;
    // Listen to the addressServer_name Ali Cloud public IP address; location / {/ / root directory
        root /usr/share/nginx/html;
        // Set the default page
        index index.html
    }
    
    // Interface forwarding
    location ~ /api/ {
    proxy_pass http:// Aliyun public IP address :7001; //7001 indicates the port number used by Node}}Copy the code

Run nginx

// Nginx is running properly
docker run -d -p 80:80--name Nginx mirror ID// Run nginx through directory mapping
// The directories preceded by the colon ':' are the host directories, and the directories followed are the in-container directories
docker run --name nginx -d -p 80:80 -v /root/nginx/log:/var/log/nginx -v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /root/nginx/conf.d:/etc/nginx/conf.d -v /root/nginx/html:/usr/Share/nginx/HTML image idCopy the code

Generate the mirror

Docker build-t Image name: version Dockerfile pathCopy the code

Note that in ali cloud server to configure the port number corresponding situation, must pay attention to!