Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker context (directory) not set consistently? #974

Open
sherland opened this issue Mar 3, 2024 · 4 comments
Open

Docker context (directory) not set consistently? #974

sherland opened this issue Mar 3, 2024 · 4 comments

Comments

@sherland
Copy link

sherland commented Mar 3, 2024

I'm new to Nx, so not sure if / how this is supposed to work, but here goes:
I want to create a nginx base-container that will be used by some of the other containers in the monorepo.

I create a new folder "Applications\nginx", (where all the other applications are located) and added package.json and project.json. (Content at the end)

Then I add a nginx.conf with appropriate content, and created the Dockerfile with this content:

FROM docker.io/nginx:stable-alpine
COPY /nginx.conf /etc/nginx/nginx.conf

By coincidence, I was in the Applications\nginx directory. when I ran nx run nginx-base-image:container

This was working as it should. However then I navigated to the root of the project and ran nx run nginx-base-image:container again. Now the container could not be built. I had to change Dockerfile to this:

FROM docker.io/nginx:stable-alpine
COPY Applications/nginx/nginx.conf /etc/nginx/nginx.conf

Does this mean that the docker build context is just set by random to whatever directory i'm starting the build from?

BTW: I'm using Rancher Desktop, not Docker Desktop, and I get this to the console when building:

>  Buildx version 
[command]"C:\Program Files\Rancher Desktop\resources\resources\win32\bin\docker.exe" buildx version
github.com/docker/buildx v0.12.0 542e5d810e4a1a155684f5f3c5bd7e797632a12f
Unsupported CI Provider... Using Local Environment as fallback
[command]"C:\Program Files\Git\cmd\git.exe" log -1 --pretty=format:%ae
[email protected][command]"C:\Program Files\Git\cmd\git.exe" symbolic-ref HEAD
refs/heads/master
[command]"C:\Program Files\Git\cmd\git.exe" rev-parse HEAD
01ea355452c4bce35ce9916d50ce46d08d7a4b54

--- Other files
package.json:

{
  "name": "nginx-base-image",
  "version": "1.0.0",
  "scripts": {},
  "author": "Team Triton",
  "dependencies": {},
  "devDependencies": {},
  "browser": {}
}

project.json:

{
  "name": "nginx-base-image",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "prefix": "",
  "targets": {
    "container": {
      "executor": "@nx-tools/nx-container:build",
      "dependsOn": [],
      "options": {
        "engine": "docker",
        "metadata": {
          "images": ["nginx-base-image"],
          "load": true,
          "tags": [
            "type=schedule",
            "type=ref,event=branch",
            "type=ref,event=tag",
            "type=ref,event=pr",
            "type=sha,prefix=sha-"
          ]
        }
      }
    }
  }
}
@patrickmichalina
Copy link

Not sure if the same issue but as of NX 20.0.0 I cannot use this tool as it appears to be referencing the root DOCKERFILE to build apps which are normally pointing to their own app-level dockerfile.

@stefanellid-mms
Copy link

Any news on the issue in 20.0.0?

@patrickmichalina
Copy link

Just to let people know if you manually set the context reference in the project.json you can overcome what was before a default to the project. It unblocks the migration to NX

@ThorstenKunz
Copy link

ThorstenKunz commented Dec 13, 2024

Just to let people know if you manually set the context reference in the project.json you can overcome what was before a default to the project. It unblocks the migration to NX

Can you maybe please show how the config would look like? We just upgraded to 20 and no matter what options we set we always get the error that the Dockerfile can't be found. Our Dockerfiles are all in each app's root directory and everything was working fine until the upgrade to 20.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants