Github 操作 - Docker 构建:在构建上下文中找不到文件或已排除文件
Github Action - Docker build: file not found in build context or excluded
我的 Github 操作有问题,我在构建我的 jar 后尝试构建我的 Docker 图像并抛出此错误:
Step 8/9 : COPY /home/runner/work/js-sites-client-api/js-sites-client-api/build/libs/client-portal-api.jar app.jar
COPY failed: file not found in build context or excluded by .dockerignore: stat home/runner/work/js-sites-client-api/js-sites-client-api/build/libs/client-portal-api.jar: file does not exist
这对我来说没有意义,因为我 运行 LS/PWD 并且我可以看到文件在那里:
ls build/libs
cd build/libs
pwd
cd ../../
docker build . --file Dockerfile --tag ***/js-client-api:latest
shell: /usr/bin/bash -e {0}
env:
JAVA_HOME: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/11.0.14-1/x64
GRADLE_BUILD_ACTION_CACHE_RESTORED: true
-------------OUTPUT of ls/pwd------------
client-portal-api.jar
/home/runner/work/js-sites-client-api/js-sites-client-api/build/libs
下面是我的github操作:
...
jobs:
build:
...
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Change wrapper permissions
run: chmod +x ./gradlew
- name: Build with Gradle
uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7
with:
arguments: build
- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build the Docker image
run: |
ls build/libs
cd build/libs
pwd
cd ../../
docker build . --file Dockerfile --tag ${{ secrets.DOCKER_USERNAME }}/js-client-api:latest --build-arg WORKDIR=${{ github.workspace }}
- name: Push the Docker image
run: docker push ${{ secrets.DOCKER_USERNAME }}/js-client-api:latest
如有任何帮助,我们将不胜感激!
Dockerfile 中的这一行是问题所在:
COPY /home/runner/work/js-sites-client-api/js-sites-client-api/build/libs/client-portal-api.jar app.jar
。在 Dockerfile COPY
中,第一个参数是文件在机器上的位置,它必须是相对路径,而不是绝对路径。阅读更多 here
Multiple resources may be specified but the paths of files and directories will be interpreted as relative to the source of the context of the build.
我的 Github 操作有问题,我在构建我的 jar 后尝试构建我的 Docker 图像并抛出此错误:
Step 8/9 : COPY /home/runner/work/js-sites-client-api/js-sites-client-api/build/libs/client-portal-api.jar app.jar
COPY failed: file not found in build context or excluded by .dockerignore: stat home/runner/work/js-sites-client-api/js-sites-client-api/build/libs/client-portal-api.jar: file does not exist
这对我来说没有意义,因为我 运行 LS/PWD 并且我可以看到文件在那里:
ls build/libs
cd build/libs
pwd
cd ../../
docker build . --file Dockerfile --tag ***/js-client-api:latest
shell: /usr/bin/bash -e {0}
env:
JAVA_HOME: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/11.0.14-1/x64
GRADLE_BUILD_ACTION_CACHE_RESTORED: true
-------------OUTPUT of ls/pwd------------
client-portal-api.jar
/home/runner/work/js-sites-client-api/js-sites-client-api/build/libs
下面是我的github操作:
...
jobs:
build:
...
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Change wrapper permissions
run: chmod +x ./gradlew
- name: Build with Gradle
uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7
with:
arguments: build
- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build the Docker image
run: |
ls build/libs
cd build/libs
pwd
cd ../../
docker build . --file Dockerfile --tag ${{ secrets.DOCKER_USERNAME }}/js-client-api:latest --build-arg WORKDIR=${{ github.workspace }}
- name: Push the Docker image
run: docker push ${{ secrets.DOCKER_USERNAME }}/js-client-api:latest
如有任何帮助,我们将不胜感激!
Dockerfile 中的这一行是问题所在:
COPY /home/runner/work/js-sites-client-api/js-sites-client-api/build/libs/client-portal-api.jar app.jar
。在 Dockerfile COPY
中,第一个参数是文件在机器上的位置,它必须是相对路径,而不是绝对路径。阅读更多 here
Multiple resources may be specified but the paths of files and directories will be interpreted as relative to the source of the context of the build.