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

Nerdctl can't find .env file #1213

Closed
benjaminpreiss opened this issue Jan 8, 2022 · 14 comments
Closed

Nerdctl can't find .env file #1213

benjaminpreiss opened this issue Jan 8, 2022 · 14 comments
Assignees
Labels
kind/bug Something isn't working platform/windows
Milestone

Comments

@benjaminpreiss
Copy link

Rancher Desktop Version

0.7.1

Rancher Desktop K8s Version

1.22.5

What operating system are you using?

Other (specify below)

Operating System / Build Version

WSL2 debian on Windows 10 professional

What CPU architecture are you using?

x64

Windows User Only

No response

Actual Behavior

nerdctl compose can not find my .env file even though specifying it via the --env-file option

Steps to Reproduce

Create a basic docker-compose.yml e.g.

version: "3.9"
services:
  web:
    build: .
    ports:
      - "5000:5000"
  redis:
    image: "redis:alpine"

Create a .env file in the same directory. e.g.

# .env file
PROJECT_NAME=test_project

Run command nerdctl compose -f ./docker-compose.yml config --env-file ./.env

Result

I get an error "FATA[0000] Couldn't find env file: ./.env"

Expected Behavior

The config should be displayed according to the docker-compose.yml

Additional Information

No response

@benjaminpreiss benjaminpreiss added the kind/bug Something isn't working label Jan 8, 2022
@jandubois jandubois added this to the v1.0.0 milestone Jan 8, 2022
@ericpromislow ericpromislow self-assigned this Jan 21, 2022
@ericpromislow ericpromislow added the triage/not-reproducible Not (or no longer) reproducible label Jan 21, 2022
@ericpromislow
Copy link
Contributor

Unfortunately, running rancher-desktop 1.0.0 I can't reproduce this issue, running the command from both the WSL and powershell sides. I'm closing this issue now, but if it's still a problem with the current version, and/or there are pertinent messages in the log files, please feel free to reopen it.

@benjaminpreiss
Copy link
Author

benjaminpreiss commented Jan 21, 2022

@ericpromislow hmm, is there v1.0.0 out now for windows? The version I ran it from was 0.7.1

edit: I can see that it is in beta now. Will try. thanks!

@ericpromislow
Copy link
Contributor

Great!

@benjaminpreiss
Copy link
Author

benjaminpreiss commented Jan 25, 2022

Hey @ericpromislow. On my side, the problem still persists, even with the new version... :( I forgot to mention that I am using containerd and not moby...

@benjaminpreiss
Copy link
Author

I think this issue is somehow related?

#1279

@benjaminpreiss
Copy link
Author

I tried to run it with debug:

nerdctl compose -f ./docker-compose.yml up --build --env-file ./config-dev.env --debug

The only thing shown is:

DEBU[0000] found CNI isolation plugin
FATA[0000] Couldn't find env file: ./config-dev.env

@ericpromislow
Copy link
Contributor

Hi, nerdctl brings up a problem trying to hit containerd.sock when running in moby mode.

This doesn't look exactly like #1279 unless there are some environment variables that nerdctl picks up that I don't know about. Are there?

When I run with --debug I also see

DEBU[0000] found CNI isolation plugin

but then it echoes the contents of the combined config file. This is with nerdctl version 0.16.0 on both macos and Ubuntu/WSL.

If I run the command from a different directory, I get the error message complaining about the missing .env file, even though there's no docker-compose.yml either -- it doesn't get to the point of trying to read that file.

Are you running the command in the same directory, or is this directory mounted at a point other than /mnt/c or /mnt/wsl` ?

@ericpromislow ericpromislow reopened this Jan 25, 2022
@jandubois
Copy link
Member

Hi, nerdctl brings up a problem trying to hit containerd.sock when running in moby mode.

@ericpromislow You cannot use nerdctl with moby, we do not support this.

@benjaminpreiss already confirmed that they are running with containerd though. Can you reproduce the problem in that configuration?

Since this is on Windows, it sounds like it is a problem with nerdctl-stub, which will have to translate the Windows path to a Linux path.

@ericpromislow
Copy link
Contributor

I was running the command from the Ubuntu side. In Powershell running .... .\.env reproduces the issue. Running ... ./.env with a forward slash works fine. The .\docker-compose.yml part is resolved with either kind of slash.

@jandubois jandubois removed the triage/not-reproducible Not (or no longer) reproducible label Jan 25, 2022
@gaktive gaktive modified the milestones: v1.0.0, v1.0.1 Jan 25, 2022
@ericpromislow
Copy link
Contributor

The --env-file ENVFILE part needs to appear before config.

It's not obvious from the nerdctl help:
``
$ nerdctl compose --help
Compose

Usage:
nerdctl compose [flags]
nerdctl compose [command]
Management commands:
Commands:
build Build or rebuild services
config Validate and view the Compose file

Flags:
--env-file string Specify an alternate environment file
-f, --f string Alias of --file


Those two usage lines are not too helpful if you want to specify both flags and a command. Let's see what docker says:

$ docker compose --help

Usage: docker compose [OPTIONS] COMMAND

Docker Compose

Options:
--ansi string Control when to print ANSI control characters ("never"|"always"|"auto") (default "auto")
--env-file string Specify an alternate environment file.
-f, --file stringArray Compose configuration files
...


So doing `nerdctl compose -f .\docker-compose.yml --env-file .\.env config` should work.

What's happening is that the windows stub stops processing paths when it hits the `config` directive, as it assumes that there are no more options afterwards. I'm not sure if this is a bug or by design, so leaving this open. But if you put `config` at the end, it should work.

@benjaminpreiss
Copy link
Author

@ericpromislow You are absolutely right! It works now, when using --env-file in the right place... I was just so confused by the nerdctl docs, maybe I should request clarification on that there!

@ericpromislow
Copy link
Contributor

It was also a bug on our side -- our code wasn't handling the path-type arguments correctly when they appeared to the right of the secondary command (in this case config). But the nerdctl docs should actually nail down the supported CLI syntax.

@ericpromislow
Copy link
Contributor

Not merged yet.

@ericpromislow ericpromislow reopened this Jan 26, 2022
@ericpromislow
Copy link
Contributor

Closed in #1332

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working platform/windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants