[英]How do I use Docker with GitHub Actions?
當我創建 GitHub 操作工作流文件時,示例 YAML 文件包含runs-on: ubuntu-latest
。 根據文檔,我只能在 Ubuntu、Windows Server 和 macOS X 的幾個版本之間進行選擇。
我認為 GitHub Actions 在 Docker 中運行。 如何選擇我的 Docker 鏡像?
GitHub 操作提供了一個虛擬機——正如你所指出的,無論是 Ubuntu、Windows 還是 macOS——並在其中運行你的工作流程。 然后,您可以使用該虛擬機在容器內運行工作流。
使用container
說明符在container
內運行一個步驟。 確保將runs-on
指定為容器的適當主機環境(對於 Linux 容器為ubuntu-latest
,對於 Windows 容器為windows-latest
)。 例如:
jobs:
vm:
runs-on: ubuntu-latest
steps:
- run: |
echo This job does not specify a container.
echo It runs directly on the virtual machine.
name: Run on VM
container:
runs-on: ubuntu-latest
container: node:10.16-jessie
steps:
- run: |
echo This job does specify a container.
echo It runs in the container instead of the VM.
name: Run in container
作業(作為工作流的一部分)在虛擬機內運行。 您選擇他們提供的環境之一(例如ubuntu-latest
或windows-2019
)。
一項工作由一個或多個步驟組成。 一個步驟可能是一個簡單的 shell 命令,使用run 。 但它也可能是一個動作,使用用途
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
run: <COMMAND>
使用操作系統的 shell 執行命令uses: actions/checkout@v1
運行來自存儲庫checkout
( https://github.com/actions/checkout )中的用戶/組織actions
,主要版本 1uses: ./.github/actions/my-action
運行此路徑下您自己的存儲庫中定義的操作uses: docker://continuumio/anaconda3:2019.07
從 Docker Hub ( https://hub.docker.com/r/continuumio/anaconda3 ) 運行用戶/組織continuumio
的anaconda3
映像,版本2019.07
請記住,如果要使用 Docker,則需要選擇 linux 發行版作為環境。
還應該注意的是,有一個container
選項,允許您運行通常在主機上運行的任何步驟以在容器內運行: https : //help.github.com/en/articles/workflow-syntax- for-github-actions#jobsjob_idcontainer
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.