如何通过 CircleCI 在 Ubuntu 运行 内启动 Redis

How to start Redis within Ubuntu run via CircleCI

我有以下 CircleCI 配置(这是修剪过的,我不包括失败行之后的配置):

version: 2
jobs:
  build:
    working_directory: ~/mycompany/mycompany_app
    docker:
    - image: ubuntu:18.04
    steps:
    - run:
        name: Update yum cache
        command: apt-get update
    - run:
        name: Install base packages
        command: apt-get install -y sudo git wget tzdata postgresql postgresql-contrib build-essential python2.7 make gcc redis-server
    - run:
        name: Start Redis
        command: sudo service redis-server start
    - run: redis-cli ping

最后一个命令,redis-cli ping 给我错误 Could not connect to Redis at 127.0.0.1:6379: Connection refused

我能找到的关于这个问题的最佳线索是 https://github.com/Microsoft/WSL/issues/365 though that doesn't help since I'm doing the manual start as they suggest. There's also some stuff in ,它是相关的,但我不认为不使用 upstart 是我的问题。

如何启动服务器以便它响应 ping?

我通过将 sudo service redis-server start 更改为 sudo redis-server --daemonize yes 使其工作,这确实是链接 Github 问题中列出的一个选项,尽管我认为它是等效的(为了我的目的) redis-server & 所以我没试过。

要真正利用 CircleCI,您可能想尝试这样做:

version: 2
jobs:
  build:
    working_directory: ~/mycompany/mycompany_app
    docker:
      - image: ubuntu:18.04
      - image: circleci/redis:4.0.9
    steps:
    - run:
        name: Update Apt Cache
        command: apt-get update
    - run:
        name: Install base packages
        command: apt-get install -y sudo git wget tzdata postgresql postgresql-contrib build-essential python2.7 make gcc
    - run: redis-cli ping