GVKun编程网logo

让运行在 Docker 中的 Ghost 支持阿里云 OSS(阿里云 windows docker)

16

如果您想了解让运行在Docker中的Ghost支持阿里云OSS和阿里云windowsdocker的知识,那么本篇文章将是您的不二之选。我们将深入剖析让运行在Docker中的Ghost支持阿里云OSS的

如果您想了解让运行在 Docker 中的 Ghost 支持阿里云 OSS阿里云 windows docker的知识,那么本篇文章将是您的不二之选。我们将深入剖析让运行在 Docker 中的 Ghost 支持阿里云 OSS的各个方面,并为您解答阿里云 windows docker的疑在这篇文章中,我们将为您介绍让运行在 Docker 中的 Ghost 支持阿里云 OSS的相关知识,同时也会详细的解释阿里云 windows docker的运用方法,并给出实际的案例分析,希望能帮助到您!

本文目录一览:

让运行在 Docker 中的 Ghost 支持阿里云 OSS(阿里云 windows docker)

让运行在 Docker 中的 Ghost 支持阿里云 OSS(阿里云 windows docker)

https://yq.aliyun.com/articles/749679


本文使用「署名 4.0 国际 (CC BY 4.0)」许可协议,欢迎转载、或重新修改使用,但需要注明来源。 署名 4.0 国际 (CC BY 4.0)

本文作者:苏洋

创建时间: 2020 年 03 月 14 日
统计字数: 8133 字
阅读时间: 17 分钟阅读
本文链接: https://soulteary.com/2020/03/14/ghost-running-in-docker-supports-alibaba-cloud-oss.html



让运行在 Docker 中的 Ghost 支持阿里云 OSS

最近在优化 Ghost 作为线上使用的内容管理后台,作为线上使用的系统,不同于内部 MIS ,可靠性和应用性能需要有一定保障。

解决性能问题,最简单的方案便是进行水平扩展,而我们知道,如果想要让一个服务做到水平可扩展,除了要将应用运行状态单独持久化外,也必须做到文件储存的持久化,云平台的对象储存就是一个很好的文件持久化方案。

Ghost 是一个典型的单体应用,v3.x 版本的容器化文档其实不多,而介绍如何使用 Aliyun OSS 的文档更是没有,折腾过程还是挺有趣的,记录下来,希望能够帮助到后面有需求的同学。

写在前面

官方文档在使用三方自定义储存部分其实写的不是很好:

  1. 文档有效性不敢恭维,虽然内容中提到支持阿里云,但是列表中的阿里云 OSS 插件仅针对于 1.x 版本,其中阿里云的 SDK 也比较旧,当时的 Node 环境也很陈旧。
  2. 自定义文档缺少技术细节、以及完整描述,需要通过实践和阅读源码去验证。
  3. 完全没提到如何在容器镜像,尤其是官方镜像中使用插件。

本文将通过相对流程化的容器方案,来解决以上问题。

之前的文章《从定制 Ghost 镜像聊聊优化 Dockerfile》、修理 Ghost 中文输入法的 BUG 有提过,“如何对 Ghost 进行容器化封装”,感兴趣的同学可以了解下。

在 “反复横跳” 踩了一堆坑之后,相对稳妥的低成本维护方案便是为 Ghost 编写适合当前版本的储存插件,并制作基于官方容器镜像的补丁镜像了。

在编写插件之前,需要先确认官方环境中的 Node 版本,以确定符号语法:

docker run --rm -it --entrypoint /usr/local/bin/node ghost:3.9.0-alpine -v

执行完上述命令,你将得到 v12.16.1 的结果,看来可以直接使用 async/await 来编写插件减少代码量了。

编写 OSS 储存插件

参考官方模版,以及阿里云 OSS SDK 完成储存插件大概十几分钟就搞定了,相关代码我已经上传至 GitHub,如果需要二次封装,可以参考使用。

/**
 * Ghost v3 Storage Adapter (Aliyun OSS)
 * @author soulteary(soulteary@gmail.com)
 */

const AliOSS = require("ali-oss");
const GhostStorage = require("ghost-storage-base");
const { createReadStream } = require("fs");
const { resolve } = require("path");

class AliOSSAdapter extends GhostStorage {
  constructor(config) {
    super();
    this.config = config || {};
    this.oss = new AliOSS({
      region: config.region,
      accessKeyId: config.accessKeyId,
      accessKeySecret: config.accessKeySecret,
      bucket: config.bucket
    });

    this.ossURL = `${config.bucket}.${config.region}.aliyuncs.com`;
    this.regexp = new RegExp(`^https?://${this.ossURL}`, "i");
    this.domain = config.domain || null;
    this.notfound = config.notfound || null;
  }

  async exists(filename, targetDir = this.getTargetDir("/")) {
    try {
      const { status } = await this.oss.head(resolve(targetDir, filename));
      return status === 404;
    } catch (err) {
      return false;
    }
  }
  delete() {
    // it''s unnecessary
    // Ghost missing UX
  }
  serve() {
    return function(req, res, next) {
      next();
    };
  }

  async read(options) {
    try {
      const { meta } = await this.oss.head(options.path);
      if (meta && meta.path) {
        return meta.path;
      } else {
        return this.notfound;
      }
    } catch (err) {
      console.error(`Read Image Error ${err}`);
      return this.notfound;
    }
  }

  async save(image, targetDir = this.getTargetDir("/")) {
    try {
      const filename = await this.getUniqueFileName(image, targetDir);
      const { url } = await this.oss.put(filename, createReadStream(image.path));

      if (url && url.indexOf(`://${this.ossURL}`) > -1) {
        return this.domain ? url.replace(this.regexp, this.domain) : url;
      } else {
        return this.notfound;
      }
    } catch (err) {
      console.error(`Upload Image Error ${err}`);
      return this.notfound;
    }
  }
}

module.exports = AliOSSAdapter;

这里支持的配置内容有:

{
  "storage": {
    "active": "ghost-aliyun-oss-store",
    "ghost-aliyun-oss-store": {
      "accessKeyId": "YOUR_ACCESS_KEY_ID",
      "accessKeySecret": "YOUR_ACCESS_SERCET",
      "bucket": "YOUR_BUCKET_NAME",
      "region": "oss-cn-beijing",
      "domain": "https://your-public-domian",
      "notfound": "https://s3-img.meituan.net/v1/mss_3d027b52ec5a4d589e68050845611e68/ff/n0/0k/4n/3s_73850.jpg"
    }
  }
}

其中 domian、是可选项,如果你需要使用 CDN 域名,请在这个字段里配置。

封装支持 OSS 插件的镜像

为了保证运行镜像性能足够高、尺寸相对较小,我们需要使用 docker multistage build 方案。

先定义基础镜像,并安装刚刚编写的 Ghost Aliyun OSS 插件。

FROM ghost:3.9.0-alpine as oss
LABEL maintainer="soulteary@gmail.com"
WORKDIR $GHOST_INSTALL/current
RUN su-exec node yarn --verbose add ghost-aliyun-oss-store

接着定义运行使用的镜像。

FROM ghost:3.9.0-alpine
LABEL maintainer="soulteary@gmail.com"
COPY --chown=node:node --from=oss $GHOST_INSTALL/current/node_modules $GHOST_INSTALL/current/node_modules
RUN mkdir -p $GHOST_INSTALL/current/content/adapters/storage/
RUN echo "module.exports = require(''ghost-aliyun-oss-store'');" > $GHOST_INSTALL/current/content/adapters/storage/ghost-aliyun-oss-store.js

参考之前的两篇文章,如果想解决 “不能正常进行中文输入” 的问题,并且提取出了构建后的内容,可以在镜像中添加下面的内容:

COPY ./docker-assets/admin-views  $GHOST_INSTALL/current/core/server/web/admin/views
COPY ./docker-assets/built/assets $GHOST_INSTALL/current/core/built/assets

如果你不希望将配置单独抽象为文件,可以添加下面的内容。

RUN set -ex; \
    su-exec node ghost config storage.active ghost-aliyun-oss-store; \
    su-exec node ghost config storage.ghost-aliyun-oss-store.accessKeyId YOUR_ACCESS_KEY_ID; \
    su-exec node ghost config storage.ghost-aliyun-oss-store.accessKeySecret YOUR_ACCESS_SERCET; \
    su-exec node ghost config storage.ghost-aliyun-oss-store.bucket YOUR_BUCKET_NAME; \
    su-exec node ghost config storage.ghost-aliyun-oss-store.region oss-cn-beijing; \
    su-exec node ghost config storage.ghost-aliyun-oss-store.domain https://your-public-domian; \
    su-exec node ghost config storage.ghost-aliyun-oss-store.notfound https://s3-img.meituan.net/v1/mss_3d027b52ec5a4d589e68050845611e68/ff/n0/0k/4n/3s_73850.jpg; \
    su-exec node ghost config privacy.useUpdateCheck false; \
    su-exec node ghost config privacy.useGravatar false; \
    su-exec node ghost config privacy.useRpcPing false; \
    su-exec node ghost config privacy.useStructuredData false; \

当然,为了更方便更新内容,抽象为单独的文件是更好的选择,比如像下面这样编写 config.production.json 配置文件。

{
  "server": {
    "port": 2368,
    "host": "0.0.0.0"
  },
  "privacy": {
    "useUpdateCheck": false,
    "useGravatar": false,
    "useRpcPing": false,
    "useStructuredData": false
  },
  "storage": {
    "active": "ghost-aliyun-oss-store",
    "ghost-aliyun-oss-store": {
      "accessKeyId": "YOUR_ACCESS_KEY_ID",
      "accessKeySecret": "YOUR_ACCESS_SERCET",
      "bucket": "baai-news-upload",
      "region": "oss-cn-beijing",
      "domain": "https://your-public-domian",
      "notfound": "https://s3-img.meituan.net/v1/mss_3d027b52ec5a4d589e68050845611e68/ff/n0/0k/4n/3s_73850.jpg"
    }
  }
}

完整的容器编排文件

上面聊了许多定制化的选项,那么一个最小可用的容器编排配置是什么样的呢?其实大概不到十行,就足以满足我们的基础需求。

FROM ghost:3.9.0-alpine as oss
WORKDIR $GHOST_INSTALL/current
RUN su-exec node yarn --verbose add ghost-aliyun-oss-store

FROM ghost:3.9.0-alpine
LABEL maintainer="soulteary@gmail.com"
COPY --chown=node:node --from=oss $GHOST_INSTALL/current/node_modules $GHOST_INSTALL/current/node_modules
RUN mkdir -p $GHOST_INSTALL/current/content/adapters/storage/
RUN echo "module.exports = require(''ghost-aliyun-oss-store'');" > $GHOST_INSTALL/current/content/adapters/storage/ghost-aliyun-oss-store.js

将上面的内容保存为 Dockerfile,如果需要其他的功能,可以参考上面的内容进行适当修改。

docker build -t soulteary/ghost-with-oss:3.9.0 -f Dockerfile .

执行上面的命令,稍等片刻,一个衍生自 Ghost 官方镜像,支持 OSS 的容器镜像就构建完毕了。

如何使用镜像

这里给出一个完整编排文件供大家参考,如果不想使用 Traefik,只需要将端口单独暴露出来即可。

至于 Traefik 如何使用,参考我以往的文章,熟悉之后,你将会发现一片新的天地。

version: "3.6"

services:

  ghost-with-oss:
    image: soulteary/ghost-with-oss:3.9.0
    expose:
      - 2368
    environment:
      url: https://ghost.lab.io
      database__client: mysql
      database__connection__host: ghost-db
      database__connection__port: 3306
      database__connection__user: root
      database__connection__password: ghost
      database__connection__database: ghost
      NODE_ENV: production
    volumes:
      # 这里参考前篇文章,或者本篇文章内容,选择性使用
      # 解决 Ghost 中文输入的问题
      # - ./docker-assets/built/assets:/var/lib/ghost/versions/current/core/built/assets:ro
      # - ./docker-assets/admin-views:/var/lib/ghost/current/core/server/web/admin/views:ro
      - ./config.production.json:/var/lib/ghost/config.production.json    
    extra_hosts:
      - "ghost.lab.io:127.0.0.1"
    networks:
      - traefik
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik"
      - "traefik.http.routers.ghostweb.entrypoints=http"
      - "traefik.http.routers.ghostweb.middlewares=https-redirect@file"
      - "traefik.http.routers.ghostweb.rule=Host(`ghost.lab.io`)"
      - "traefik.http.routers.ghostssl.middlewares=content-compress@file"
      - "traefik.http.routers.ghostssl.entrypoints=https"
      - "traefik.http.routers.ghostssl.tls=true"
      - "traefik.http.routers.ghostssl.rule=Host(`ghost.lab.io`)"
      - "traefik.http.services.ghostbackend.loadbalancer.server.scheme=http"
      - "traefik.http.services.ghostbackend.loadbalancer.server.port=2368"

networks:
  traefik:
    external: true

将上面内容保存为 docker-compose.yml,使用 docker-compose up -d 启动应用,最后访问配置里定义的域名即可开始使用这个支持 OSS 功能的 Ghost 。

当然,如果你没有线上数据库,也可以使用 docker-compose 启动一个数据库:

version: ''3''
services:

  db:
    image: mysql:5.7
    container_name: ghost-db
    expose:
      - 3306
    networks:
      - traefik
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ghost
    volumes:
      - ./localdb:/var/lib/mysql

networks:
  traefik:
    external: true

最后

本篇内容,以封装 Ghost 定制镜像简单说明了如何基于官方镜像进行扩展,并简单示范了 Docker Multistage Build,以及 Ghost 3.x 版本如何使用 Aliyun OSS。

或许下一篇内容会聊聊,Ghost 这类原本不支持 SSO 单点登录的应用如何快速接入 SSO。

--EOF

3. docker-compose实战--ghost app

3. docker-compose实战--ghost app

一. registry介绍

1. 先来了解术语

host 宿主机 image 镜像 container 容器 regisry 仓库 daemon 守护进程 client 客户端

 

 2. docker与Registry的交互命令

  • docker search Nginx: 搜索镜像
  • docker pull Nginx: 拉取镜像到本地
  • docker push myname/Nginx: 提交镜像到自己的仓库

 3. 常用docker镜像的仓库

  • docker hub(官方提供)
  • daocloud(国内)
  • 时速云(国内)
  • aliyun(国内)

4. 如何将本地镜像上传到镜像库

使用命令

docker tag local-image:tagname new-repo:tagname
docker push new-repo:tagname

首先,使用tag给本地镜像起一个新的镜像名字和版本

第二: 使用git push将新的镜像push到自己的仓库

 

举个例子:

将本地的whalesay打包成一个自定义的tag标签的名字. 然后上传到docker 仓库

 

提示没有权限,那么需要先登录

docker login

  先登录再上传

 

5. 搜索镜像

在搜索栏输入MysqL,可以看到MysqL的基本信息. 在这下面有对MysqL的基本操作

 

 

 

这些内容都是很全面的.  

 

二. docker-compose

docker-compose是独立于docker的程序,Mac/Windows是自带到的. linux需要自己下载,下载地址:

curl https://github.com/docker/compose/releases/download/1.9.0/docker-compose-$(name -s) - $(uname -m) > /usr/local/bin/docker-compose

 

我的是mac,直接在mac上检查是否已经安装了docker-compose

docker-compose --version

说明在mac上docker-compose已经安装了

 

 

docker-compose实战 : 安装一个ghost app应用程序

实战的项目是一个ghost博客项目. 他依赖的环境是Nginx,也就是在Nginx中运行,使用的数据库是MysqL数据库.

这个项目做好了以后,我们就可以拥有自己的博客平台了. 哈哈哈....不用再在别人的博客平台写博客了.我是这么觉得的.

不过还要看看,这个平台好不好用.

如图: 我们会用到三个容器,1 Nginx服务器. 2. 博客ghost app容器 3. MysqL容器 

 1. 创建项目文件夹ghost

首先准备一个项目文件夹ghost,并在文件夹下面准备三个目录 ghost,Nginx,data

  • ghost: 用来存放拉取的ghost镜像文件
  • Nginx:用来存放pull下来的Nginx镜像文件
  • data: 挂载到MysqL镜像上的数据库目录

 

2. 准备ghost镜像

进入ghost镜像目录,编写Dockerfile

FROM ghost 直接拉取官方的ghost镜像
copY ./config.js /var/lib/ghost/content/config.js     copy本地文件到镜像目录
EXPOSE 2368        项目的端口是2368
#CMD "npm",start--production"    运行启动命令
  • FROM ghost : 直接拉取官方的ghost镜像,这里的依赖如果本地没有,会直接去镜像看pull

  • copY ./config.js /var/lib/ghost/config.js : copy本地文件到镜像目录

  • EXPOSE 2368: 项目的端口是2368

  • CMD "npm","start","--production" : 运行启动命令

准备文件config.js

var path = require('path'),config;

config = {
  production: {
    url: http://mytestblog.com,mail: {},database: {
      client: MysqLdbMysqL的名称
        user: ghost3306utf8
      }
      debug: false
    },paths: {
      contentPath: path.join(process.env.GHOST_CONTENT,/)
    },server: {
      host: 0.0.0.02368
    }
  }
};

module.exports = config;

这个文件的内容,替换原始文件内容,指定了博客的url,连接数据库的基本信息.服务的ip和端口号

 

 3. 准备Nginx镜像

首先,配置Dockerfile文件

FROM Nginx
copY Nginx.conf /etc/Nginx/Nginx.conf
EXPOSE 80

 这个镜像不说了,含义和上面的基本差不多

这里多说一句,我们不需要启动命令了,因为Nginx中自带了启动命令

 

准备Nginx.conf命令 

worker_processes 4;
events {
  worker_connections 1024;    
}

http {
    server {
        listen 80;
        location / {
            proxy_pass http:ghost-app:2368;
        }
    } 
}

 

4. 准备一个docker-compose文件,这个文件就是描述系统的架构的 

version : 2'    因为docker-compose在发展中的工具,他的语法有第一版和第二版,我们这里使用的语法是第二版

networks:   显示声明一个网络,网络名叫ghost
  ghost:

services:   一共有三个服务,ghost-app服务,Nginx服务,MysqL服务
  ghost-app:
    build: ghost    这个服务是怎么来的呢? 他是build来的,我们之前提供了dockerfile文件和配置文件. 通过build得来. 那么去哪里构建呢? 请进入到ghost目录进行构建.
    networks:
      - ghost    指定ghost网络
    depends_on:   描述依赖关系. 启动的时候,先启动db. 再启动ghost-app,最后启动Nginx
      - db    
    ports:
      - 2368:2368"

  Nginx:
    build: Nginx     Nginx也是从文件构建,我们已经写好了Dockerfile
    networks: 
      - ghost
    depends_on:
      - ghost-app
    ports:
      - 80:80

  db:   数据库描述. 这里的名字一定是db,因为前面有文件调用了这个名字
    image: MysqL:5.7.15"    MysqL不是build,而是直接去pull一个image
    networks:
      - ghost
    environment:
      MysqL_ROOT_PASSWORD: MysqLroot
      MysqL_USER: ghost
      MysqL_PASSWORD: ghost
    volumes:    挂载MysqL数据目录
      - $PWD/data:/var/lib/MysqL
    ports:
      - 3306:3306"

这里的注意事项如下:

  •  version : '2' -->因为docker-compose在发展中的工具,我们这里使用的语法是第二版
  • build: ghost --> 这个服务是怎么来的呢? 他是build来的,我们之前提供了dockerfile文件和配置文件. 通过build得来. 那么去哪里构建呢? 请进入到ghost目录进行构建.

  •  db: 数据库描述. 这里的名字一定是db,因为前面有文件调用了这个名字

 5. 启动docker-compose

docker-compose up -d  -d表示从后台启动
  • -d: 表示在后台启动,退出客户端不会关闭

 三个容器都启动了. 

 

构建镜像

docker-compose build

停止运行

docker-compose stop

查看启动的容器

docker-compose ps 

查看所有容器

docker-compose ps -a

整了好久,没运行起来,今早上,终于运行起来了

原因有两点: 

第一个是ghost的config.js拷贝文件的地址变了:  原来是copY ./config.js /var/lib/ghost/config.js  改为  copY ./config.js /var/lib/ghost/content/config.js

第二个是注释掉ghost的Dockerfile中的这句话: # CMD "npm","--production"

再重启项目,启动起来了. 

FROM ghost
copY ./config.js /var/lib/ghost/content/config.js
EXPOSE 2368
# CMD "

整个项目的代码可以参考: https://github.com/Albert-W/dockerGhost

浏览器访问http://localhost 查看Nginx页面

 

CentOS 7 使用阿里云 yum 源安装 docker

CentOS 7 使用阿里云 yum 源安装 docker

阿里云 Docker 安装文档

官方 Docker 安装文档

docker 命令 tab 补全

CentOS 7 需要安装命令补全工具:

## 安装补全工具
[root@DockerDEV01 ~]# yum install bash-com* -y

以上命令只是安装了两个包 bash-completionbash-completion-extras 来增强 bash 的 tab 命令补全功能,安装之后重新登录 shell 就可以像 Ubuntu 一样使用 tab 补全 docker 命令。

CentOS7 docker.repo 用阿里云Docker Yum源

CentOS7 docker.repo 用阿里云Docker Yum源

yum安装软件的时候经常出现找不到镜像的情况

https://download.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 12] Timeout on 

解决方法:更新/etc/yum.repos.d目录下的docker.repo文件内容,使用阿里的镜像源

[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-edge-debuginfo]
name=Docker CE Edge - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-edge-source]
name=Docker CE Edge - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

 如果是CentOS-Base.repo,则改成

 1 # CentOS-Base.repo
 2 #
 3 # The mirror system uses the connecting IP address of the client and the
 4 # update status of each mirror to pick mirrors that are updated to and
 5 # geographically close to the client.  You should use this for CentOS updates
 6 # unless you are manually picking other mirrors.
 7 #
 8 # If the mirrorlist= does not work for you, as a fall back you can try the 
 9 # remarked out baseurl= line instead.
10 #
11 #
12  
13 [base]
14 name=CentOS-$releasever - Base - mirrors.aliyun.com
15 failovermethod=priority
16 baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
17         http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
18         http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
19 gpgcheck=1
20 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
21  
22 #released updates 
23 [updates]
24 name=CentOS-$releasever - Updates - mirrors.aliyun.com
25 failovermethod=priority
26 baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
27         http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
28         http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
29 gpgcheck=1
30 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
31  
32 #additional packages that may be useful
33 [extras]
34 name=CentOS-$releasever - Extras - mirrors.aliyun.com
35 failovermethod=priority
36 baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
37         http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
38         http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
39 gpgcheck=1
40 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
41  
42 #additional packages that extend functionality of existing packages
43 [centosplus]
44 name=CentOS-$releasever - Plus - mirrors.aliyun.com
45 failovermethod=priority
46 baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
47         http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
48         http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
49 gpgcheck=1
50 enabled=0
51 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
52  
53 #contrib - packages by Centos Users
54 [contrib]
55 name=CentOS-$releasever - Contrib - mirrors.aliyun.com
56 failovermethod=priority
57 baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
58         http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
59         http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
60 gpgcheck=1
61 enabled=0
62 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

或者

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

 

CentOS7 用阿里云 Docker Yum 源在线安装 Docker 17.03.2

CentOS7 用阿里云 Docker Yum 源在线安装 Docker 17.03.2

 

 
 

 

  • 参考文档
  • 安装步骤
    • 删除已安装的 Docker
    • 配置阿里云 Docker Yum 源
    • 安装指定版本
    • 启动 Docker 服务

 

参考文档

  • 官方 Docker 安装文档:https://docs.docker.com/install/linux/docker-ce/centos
  • 阿里云 Docker 安装文档:https://yq.aliyun.com/articles/110806

安装步骤

删除已安装的 Docker

# Uninstall installed docker
sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

 

 

配置阿里云 Docker Yum 源

# Set up repository
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

# Use Aliyun Docker
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

 

安装指定版本

查看 Docker 版本:

yum list docker-ce --showduplicates

 

安装较旧版本(比如 Docker 17.03.2) 时需要指定完整的 rpm 包的包名,并且加上 --setopt=obsoletes=0 参数:

# Install docker
# on a new system with yum repo defined, forcing older version and ignoring obsoletes introduced by 17.06.0
yum install -y --setopt=obsoletes=0 \
   docker-ce-17.03.2.ce-1.el7.centos.x86_64 \ docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch

 

 

或安装 Docker 较新版本(比如 Docker 18.03.0) 时加上 rpm 包名的版本号部分:

sudo yum install docker-ce-18.03.0.ce

 

或安装 Docker 最新版本,无需加版本号:

sudo yum install docker-ce

 

启动 Docker 服务

# Start docker service
systemctl enable docker
systemctl start docker

关于让运行在 Docker 中的 Ghost 支持阿里云 OSS阿里云 windows docker的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于3. docker-compose实战--ghost app、CentOS 7 使用阿里云 yum 源安装 docker、CentOS7 docker.repo 用阿里云Docker Yum源、CentOS7 用阿里云 Docker Yum 源在线安装 Docker 17.03.2等相关内容,可以在本站寻找。

本文标签: