- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章docker部署crownblog项目到阿里云的方法步骤由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
。
。
1、服务器的配置 。
2、安装docker 。
官方文档: docs.docker.com/get-docker/ 。
选择对应的系统进行查看,以ubuntu 18.04 LTS为例 。
卸载旧版本 。
1
2
3
4
5
6
7
8
9
10
11
|
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.
|
添加新版本仓库 。
1
2
3
4
5
6
7
8
|
sudo
apt-get update
udo apt-get
install
\
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
|
获取官方GPG key 。
1
|
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
|
验证key,如果输出的是下列内容,则说明正确 。
1
2
3
4
5
6
|
# 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]
|
添加仓库地址(用国内的仓库下载,速度较快) 。
1
2
3
4
|
$
sudo
add-apt-repository \
"deb [arch=amd64] https:
//mirrors
.ustc.edu.cn
/docker-ce/linux/ubuntu/
\
$(lsb_release -cs) \
stable"
|
更新仓库和安装 。
1
2
3
|
$
sudo
apt-get update
$
sudo
apt-get
install
docker-ce docker-ce-cli containerd.io
|
进行验证,运行hello-world 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
$ docker pull hello-world
$ docker run hello-world
#出现以下信息,表示docker安装成功,已经可以正常运行
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/ 。
1
2
3
4
5
6
7
8
|
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
|
3、拉取镜像和创建镜像和容器编排 。
Mysql服务器的镜像 。
首先,个人非常不建议mysql用docker来部署,有几个原因:
如果非要在docker上部署mysql,可以这么做 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#首先确定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 添加数据卷
/crownBlog/datadir
是主机的数据库路径
/var/lib/mysql
是容器中的数据库路径,这一步非常重要
#进入容器配置
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的操作一样了。
|
4、创建数据库并导入数据文件 。
1
2
|
docker
cp
crownBlog.sql crownBlog-mysql:
/home
(docker
cp
第一个参数指定本地文件或者文件夹,第二个参数指定容器及容器内的目标文件夹)
|
登入容器并登录mysql: docker exec -it crownBlog-mysql mysql -uroot -p123456 。
执行sql文件 :source /home/crownBlog.sql 。
5、制作crownblog项目镜像 。
使用Xftp把后端代码上传到服务器 进入代码编写Dockerfile文件 。
1
2
3
4
5
6
7
8
9
10
11
12
|
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 数据库host改为刚才映射的数据库ip 。
6、生成镜像 。
在Dockerfile这个目录下 。
1
2
3
4
5
|
$ docker build -t crownblog .
$ docker run -d -p 8085:8085--name crownblog crownblog
#这样访问服务器IP:8085就可以访问网站了
|
到此这篇关于docker部署crownblog项目到阿里云的方法步骤的文章就介绍到这了,更多相关docker部署crownblog到阿里云内容请搜索我以前的文章或继续浏览下面的相关文章希望大家以后多多支持我! 。
原文链接:https://juejin.cn/post/6960260130185150500 。
最后此篇关于docker部署crownblog项目到阿里云的方法步骤的文章就讲到这里了,如果你想了解更多关于docker部署crownblog项目到阿里云的方法步骤的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我是一名优秀的程序员,十分优秀!