官方文档:
选择对应的系统进行查看,以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 #出现以下信息,表示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/
使用阿里镜像站来加速
地址:
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
Mysql服务器的镜像
首先,个人非常不建议mysql用docker来部署,有几个原因:
如果非要在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 添加数据卷 /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的操作一样了。
docker cp crownBlog.sql crownBlog-mysql:/home (docker cp 第一个参数指定本地文件或者文件夹,第二个参数指定容器及容器内的目标文件夹)
登入容器并登录mysql: docker exec -it crownBlog-mysql mysql -uroot -p123456
执行sql文件 :source /home/crownBlog.sql
使用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 数据库host改为刚才映射的数据库ip
在Dockerfile这个目录下
$ docker build -t crownblog . $ docker run -d -p 8085:8085--name crownblog crownblog #这样访问服务器IP:8085就可以访问网站了
到此这篇关于docker部署crownblog项目到阿里云的方法步骤的文章就介绍到这了,更多相关docker部署crownblog到阿里云内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
免责声明:本站发布的内容(图片、视频和文字)以原创、来自本网站内容采集于网络互联网转载等其它媒体和分享为主,内容观点不代表本网站立场,如侵犯了原作者的版权,请告知一经查实,将立刻删除涉嫌侵权内容,联系我们QQ:712375056,同时欢迎投稿传递力量。
Copyright © 2009-2022 56dr.com. All Rights Reserved. 特网科技 特网云 版权所有 特网科技 粤ICP备16109289号
域名注册服务机构:阿里云计算有限公司(万网) 域名服务机构:烟台帝思普网络科技有限公司(DNSPod) CDN服务:阿里云计算有限公司 百度云 中国互联网举报中心 增值电信业务经营许可证B2
建议您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流浏览器浏览本网站