Issues Creating a Basic Docker Image: "Not Found in $PATH"

Hello! I’m learning how to create Docker images using Nix and running into a few issues.

Here is my default.nix - it’s very similar to the example from nix.dev:

{ pkgs ? import <nixpkgs> { }
, pkgsLinux ? import <nixpkgs> { system = "x86_64-linux"; }
}:

pkgs.dockerTools.buildImage {
  name = "flask-demo";
  tag = "latest";

  contents = [
    pkgs.python39Packages.flask
    pkgs.bash
    pkgs.coreutils
  ];

  config = {
    Cmd = [ "${pkgs.python39Packages.flask}/bin/flask run" ];
    ExposedPorts = {
      "5000/tcp" = {};
    };
    WorkDir = "/app";
  };
}

I’m able to easily build and load this image. Here’s the command I execute to run it:

  • podman run -i --rm -v $PWD:/app localhost/flask-demo:latest

I then get the following error:

Error: crun: executable file /nix/store/wjlz86slim4mcya38lkhbgr2mzhnaikj-python3.9-Flask-2.1.2/bin/flask run
not found in $PATH: No such file or directory: OCI runtime attempted to invoke a command
that was not found

Please note that $PWD contains an app.py file, which the ‘flask run’ command should be able to find.

If I then drop into a container usingbash instead I’m able to run the flask app like so:

cd /app
flask run

Also, /nix/store/wjlz86slim4mcya38lkhbgr2mzhnaikj-python3.9-Flask-2.1.2/bin/flask also exists in the container.

Does anyone know which step I’m missing?

Shouldn’t it be

    Cmd = [ "${pkgs.python39Packages.flask}/bin/flask" "run" ];

(note that we provide two arguments instead of 1) Otherwise I guess that it tries to find an executable whose name is actually ${pkgs.python39Packages.flask}/bin/flask run with a space in it.

1 Like

Ahh, what a silly mistake. Yes, that fixed it. Thank you!