Build from Dockerfile in subdirectory
See original GitHub issueI’d like to build the Dockerfile in following path apis/report-api/Dockerfile and push to amazon-ecr. But COPY command in Dockerfile fails because it needs to run from the sub directory. I’ve tried setting working-directory option but its saying: Unexpected value ‘working-directory’. Maven build is working fine, how can build docker image and push?
Here’s files in my project structure:
pom.xml (root pom)
apis/report-api/pom.xml (sub pom)
apis/report-api/Dockerfile
apis/report-api/target/report-api-v1.war (war artifact is created after maven build)
Here’s the apis/report-api/Dockerfile
FROM openjdk:8-jre-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
RUN mkdir -p /home/spring
WORKDIR /home/spring
COPY target/*.war app.war
EXPOSE 8080
ENTRYPOINT java $JAVA_OPTS -Dfile.encoding=UTF-8 -jar app.war
Here’s the action yml file:
jobs:
path-context:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Maven clean & install
run: mvn clean install
- name: Login to ECR
uses: docker/login-action@v1
with:
registry: xxx.dkr.ecr.ap-southeast-1.amazonaws.com/xxx
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Set up docker buildx
uses: docker/setup-buildx-action@v1
- name: Build and push docker image
uses: docker/build-push-action@v2
working-directory: apis/report-api/
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
tags: |
repo:${{ github.sha }}
repo:latest
Issue Analytics
- State:
- Created 3 years ago
- Comments:19 (3 by maintainers)
Top Results From Across the Web
Build an Image - Specify Dockerfile Location · Codefresh | Docs
This pipeline checks out the source code of the repository and then builds a dockerfile found at the subfolder docker while still keeping...
Read more >Docker: Using COPY when the Dockerfile is located in a ...
This builds with the current directory . as the context, but uses the Dockerfile from the subdirectory. Share.
Read more >Docker gotcha with building a Dockerfile in sub directory
tl;dr; Watch out for .dockerignore causing no such file or directory when building Docker images. First I tried to use docker-compose :
Read more >Keep Subdirectory Structure in Dockerfile Copy | Baeldung
Learn to copy a directory into a Docker image preserving the subdirectory structure.
Read more >Compose file build reference - Docker Documentation
awesome/database docker image is built using backend sub-directory within Compose file parent folder. backend.Dockerfile file is used to define build steps, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK actually, on my side, I had to duplicate context for Dockerfile path:
Its private repo. I’ll make a small public repo and tell you later 😃