如何将Docker与GitHub Actions一起使用? [英] How do I use Docker with GitHub Actions?

查看:223
本文介绍了如何将Docker与GitHub Actions一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建GitHub Actions工作流文件时,示例YAML文件包含 runs-on:ubuntu-latest 根据文档,我只有几个版本的Ubuntu,Windows Server和macOS X之间的选项。

When I create a GitHub Actions workflow file, the example YAML file contains runs-on: ubuntu-latest. According to the docs, I only have the options between a couple versions of Ubuntu, Windows Server and macOS X.

我认为GitHub Actions在Docker中运行。如何选择我的Docker映像?

I thought GitHub Actions runs inside Docker. How do I choose my Docker image?

推荐答案

一项工作(作为的一部分)工作流程)在虚拟机中运行。您选择其中一种环境由它们提供(例如 ubuntu-latest windows-2019 )。

A job (as part of a workflow) runs inside a virtual machine. You choose one of the environments provided by them (e.g. ubuntu-latest or windows-2019).

一项工作由一个或多个步骤组成。使用 run ,一个步骤可能是一个简单的shell命令。但这也可能是操作,使用用途

A job consists of one or more steps. A step may be a simple shell command, using run. But it may also be an action, using uses

name: CI

on: [push]

jobs:
  myjob:
    runs-on: ubuntu-18.04 # linux required if you want to use docker
    steps:
    # Those steps are executed directly on the VM
    - run: ls /
    - run: echo $HOME
    - name: Add a file
      run: touch $HOME/stuff.txt
    # Those steps are actions, which may run inside a container
    - uses: actions/checkout@v1
    - uses: ./.github/actions/my-action
    - uses: docker://continuumio/anaconda3:2019.07




  • 运行:< COMMAND> 使用OS的外壳执行命令

  • 用途:actions / checkout @ v1 从存储库 checkout actions 中运行用户/组织的操作。 / code>( https://github.com/act ions / checkout ),主要版本1

  • 用途:./。github / actions / my-action 运行在您自己的存储库中在此路径下定义的操作

  • 用途:docker:// continuumio / anaconda3:2019.07 运行<$来自用户/组织的c $ c> anaconda3 图片 continuumio ,版本 2019.07 ,来自Docker Hub( https://hub.docker.com/r/continuumio/anaconda3

    • run: <COMMAND> executes the command with the shell of the OS
    • uses: actions/checkout@v1 runs the action from the user / organization actions in the repository checkout (https://github.com/actions/checkout), major release 1
    • uses: ./.github/actions/my-action runs the action which is defined in your own repository under this path
    • uses: docker://continuumio/anaconda3:2019.07 runs the anaconda3 image from user / organization continuumio, version 2019.07, from the Docker Hub (https://hub.docker.com/r/continuumio/anaconda3)
    • 请记住,您如果您想使用Docker,则需要选择Linux发行版作为环境。

      请参阅用途运行以获取更多详细信息。

      Take a look at the documentation for uses and run for further details.

      还应注意,有一个容器选项,允许您运行通常在要在容器内运行的主机上运行的任何步骤: https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idcontainer

      It should also be noted that there is a container option, allowing you to run any steps that would usually run on the host to be runned inside a container: https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idcontainer

      这篇关于如何将Docker与GitHub Actions一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆