我们打算使用 Git Actions 在每次提交时构建 Docker。
这是我们当前的 Git Actions yml:
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Navigate to app folder
run: cd app
- name: Open Directory
working-directory: app
run: |
ls -la
- name: Build docker image
run: docker build . -t app_name -f Dockerfile
我得到的错误是:
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/runner/work/git-root/app/Dockerfile: no such file or directory
但在我的ls -la
我看到 Dockerfile 存在:
total 48
drwxr-xr-x 4 runner docker 4096 Sep 15 13:03 .
drwxr-xr-x 6 runner docker 4096 Sep 15 13:03 ..
-rw-r--r-- 1 runner docker 93 Sep 15 13:03 .env-template
-rw-r--r-- 1 runner docker 655 Sep 15 13:03 Dockerfile
我努力了:
- 两者同时使用
actions/checkout@v1
and actions/checkout@v2
- cd 进入包含 Dockerfile 的目录
- 将 Dockerfile 目录设置为工作目录
为什么 docker 构建找不到我的 Dockerfile?
请参阅文档here https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsrun:
Each run
关键字代表运行器环境中的新进程和shell。当您提供多行命令时,每一行都在同一个 shell 中运行。
这意味着工作目录在cd
步。你的ls
步骤之所以有效,是因为您明确为其设置了工作目录。
你必须cd
在与构建命令相同的运行步骤中:
- name: Build docker image
run: |
cd app
docker build . -t app_name -f Dockerfile
或者你可以设置一个工作目录:
- name: Build docker image
working-directory: ./app
run: docker build . -t app_name -f Dockerfile
或者您可以为 docker 提供 dockerfile 的路径:
- name: Build docker image
run: docker build app -t app_name
默认为-f
is PATH/Dockerfile
, where PATH
is app
above.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)