question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build from Dockerfile in subdirectory

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
chymzcommented, Oct 19, 2020

OK actually, on my side, I had to duplicate context for Dockerfile path:

- name: Build & push image
  uses: docker/build-push-action@v2
    with:
      context: ./build/front
      file: ./build/front/Dockerfile
1reaction
digz6666commented, Oct 8, 2020

@digz6666 Do you have a link to your repo?

Its private repo. I’ll make a small public repo and tell you later 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found