欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

docker部署crownblog項目到阿里云的方法步驟

 更新時間:2021年05月10日 08:28:11   作者:crown  
這篇文章主要介紹了docker部署crownblog項目到阿里云的方法步驟,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

前端項目打包

  • 找到.env.production 修改為自己的ip或者域名地址
  • 執(zhí)行命令npm run build生成dist文件
  • 把dist文件拷貝到后端項目目錄下(使用go自帶的http服務來部署前端項目)

后端項目部署

一、服務器的配置

  • 購買阿里云服務器
  • 打開服務器的8085和3306端口
  • 使用Xshell登陸服務器

二、安裝docker

官方文檔: docs.docker.com/get-docker/

選擇對應的系統(tǒng)進行查看,以ubuntu 18.04 LTS為例

卸載舊版本

sudo apt-get remove docker docker-engine docker.io containerd runc

Reading package lists... Done
Building dependency tree    
Reading state information... Done
Package 'docker-engine' is not installed, so not removed
Package 'docker' is not installed, so not removed
Package 'containerd' is not installed, so not removed
Package 'docker.io' is not installed, so not removed
Package 'runc' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

添加新版本倉庫

sudo apt-get update

udo apt-get install \
  apt-transport-https \
  ca-certificates \
  curl \
  gnupg-agent \
  software-properties-common

獲取官方GPG key

# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

驗證key,如果輸出的是下列內容,則說明正確

# apt-key fingerprint 0EBFCD88

pub  rsa4096 2017-02-22 [SCEA]
   9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid      [ unknown] Docker Release (CE deb) <docker@docker.com>
sub  rsa4096 2017-02-22 [S]

添加倉庫地址(用國內的倉庫下載,速度較快)

$ sudo add-apt-repository \
  "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
  $(lsb_release -cs) \
  stable"

更新倉庫和安裝

 $ sudo apt-get update

 $ sudo apt-get install docker-ce docker-ce-cli containerd.io

進行驗證,運行hello-world

$ docker pull hello-world
$ docker run hello-world
#出現(xiàn)以下信息,表示docker安裝成功,已經(jīng)可以正常運行
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.
  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.(amd64)
  3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
  4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
 To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash
 Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/
 For more examples and ideas, visit:
 https://docs.docker.com/get-started/

使用阿里鏡像站來加速

地址:mirrors.aliyun.com/

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://XXX你的id.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

三、拉取鏡像和創(chuàng)建鏡像和容器編排

Mysql服務器的鏡像

首先,個人非常不建議mysql用docker來部署,有幾個原因:

  • 必須做數(shù)據(jù)卷的映射,千萬不能 將數(shù)據(jù)庫數(shù)據(jù)放在docker容器中運行,否則一但刪除容器數(shù)據(jù)將全部清空,所以一定要做數(shù)據(jù)持久化?。?;
  • 不利于io,數(shù)據(jù)讀寫在容器中讀寫一次,在綁定的卷中還要讀寫一次,兩倍讀寫壓力,性能上要打折扣。

如果非要在docker上部署mysql,可以這么做

#首先確定mysql是否能被搜素到,這步可以跳過,也可以在dockerhub.com中搜索
docker search mysql

#拉取鏡像
docker pull mysql  #這里默認是拉取的最新版本,如果需要特定版本可以在鏡像后面添加tag,具體版本信息可以在dockerhub.com查詢

#特定版本拉取,比如要拉取8.0.22(版本號一定要是官方放出的版本號,否則是查找不到的)
docker pull mysql:8.0.22

#這時可以查看下拉取的鏡像
docker images

#運行鏡像
docker run -d -p 3306:3306 -v /crownBlog/datadir:/var/lib/mysql --name crownBlog-mysql -e MYSQL_ROOT_PASSWORD=123456  mysql

# -d 表示后臺運行,并返回容器id
# -p 3006:3306 表示端口映射,具體為 -p 主機端口:容器端口
# --name 給容器取個名字
# -e MYSQL_ROOT_PASSWORD=password 給mysql root管理員設置密碼
# -v /crownBlog/datadir:/var/lib/mysql 添加數(shù)據(jù)卷
/crownBlog/datadir是主機的數(shù)據(jù)庫路徑
/var/lib/mysql是容器中的數(shù)據(jù)庫路徑,這一步非常重要

#進入容器配置
docker exec -it crownBlog-mysql bash

root@ed9345077e02:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.22 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

# 之后就和一般情況下mysql的操作一樣了。

四、創(chuàng)建數(shù)據(jù)庫并導入數(shù)據(jù)文件

  • 使用Xftp連接到服務器
  • 把本地的sql文件上傳到服務器
  • 使用docker cp命令把sql文件復制到容器
docker cp crownBlog.sql crownBlog-mysql:/home 
(docker cp 第一個參數(shù)指定本地文件或者文件夾,第二個參數(shù)指定容器及容器內的目標文件夾)

登入容器并登錄mysql: docker exec -it crownBlog-mysql mysql -uroot -p123456

執(zhí)行sql文件 :source /home/crownBlog.sql

五、制作crownblog項目鏡像

使用Xftp把后端代碼上傳到服務器
進入代碼編寫Dockerfile文件

FROM golang:latest
RUN go env -w GO111MODULE=on
RUN go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct

WORKDIR $GOPATH/src/crownBlog
COPY . $GOPATH/src/crownBlog

RUN go build .

EXPOSE 8085

ENTRYPOINT ["./blog"]   

配置crownblog的config文件
mod改為release

srv改為服務器ip 數(shù)據(jù)庫host改為剛才映射的數(shù)據(jù)庫ip

六、生成鏡像

在Dockerfile這個目錄下

$ docker build -t crownblog .
$ docker run -d -p 8085:8085--name crownblog crownblog

 
#這樣訪問服務器IP:8085就可以訪問網(wǎng)站了

到此這篇關于docker部署crownblog項目到阿里云的方法步驟的文章就介紹到這了,更多相關docker部署crownblog到阿里云內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • centos6使用docker部署kafka項目的方法分析

    centos6使用docker部署kafka項目的方法分析

    這篇文章主要介紹了centos6使用docker部署kafka項目的方法,結合實例形式分析了centos6環(huán)境下使用docker部署kafka項目的相關命令與使用技巧,需要的朋友可以參考下
    2020-02-02
  • Docker容器/bin/bash?start.sh無法找到not?found問題解決

    Docker容器/bin/bash?start.sh無法找到not?found問題解決

    最近在學習聯(lián)系中遇到一個問題,百度后發(fā)現(xiàn)這個需求還是挺常見的,所以下面這篇文章主要給大家介紹了關于Docker容器/bin/bash?start.sh無法找到not?found問題的解決方法,需要的朋友可以參考下
    2022-08-08
  • docker容器使用GPU方法實現(xiàn)

    docker容器使用GPU方法實現(xiàn)

    本文主要介紹了docker容器使用GPU方法實現(xiàn),文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • 聊聊Docker不適合跑?MySQL?的N個原因

    聊聊Docker不適合跑?MySQL?的N個原因

    容器是為了解決“在切換運行環(huán)境時,如何保證軟件能夠正常運行”這一問題,這篇文章主要介紹了Docker?為什么不適合跑?MySQL?有N個原因,需要的朋友可以參考下
    2022-12-12
  • 關于Docker 刪除dead狀態(tài)的容器問題及解決方案

    關于Docker 刪除dead狀態(tài)的容器問題及解決方案

    這篇文章主要介紹了Docker 刪除dead狀態(tài)的容器,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-05-05
  • CentOS 7.5下 安裝Docker 教程 詳解

    CentOS 7.5下 安裝Docker 教程 詳解

    這篇文章主要介紹了CentOS 7.5下 安裝Docker 教程 ,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-05-05
  • docker空間爆滿導致的進入容器失敗的解決方案

    docker空間爆滿導致的進入容器失敗的解決方案

    這篇文章主要介紹了docker空間爆滿導致的進入容器失敗的解決方案,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03
  • k8s和Docker關系簡單說明

    k8s和Docker關系簡單說明

    這篇文章主要介紹了k8s和Docker關系簡單說明,本文利于圖文講解的很透徹,有需要的同學可以研究下
    2021-03-03
  • docker限制容器內存的方法詳解

    docker限制容器內存的方法詳解

    在服務器中使用 docker 時,如果不對 docker 的可調用內存進行限制,當 docker 內的程序出現(xiàn)不可預測的問題時,就很有可能因為內存爆炸導致服務器主機的癱瘓,本文將介紹使用 docker 進行容器內存限制的方法,感興趣的朋友一起看看吧
    2023-11-11
  • 如何運用docker配合python開發(fā)環(huán)境實例

    如何運用docker配合python開發(fā)環(huán)境實例

    本篇文章主要介紹了如何運用docker配合python開發(fā)實例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07

最新評論