We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Dockerfile scan fails when in directory and used -f
**Describe the bug**
When running directory scan checkov shows Dockerfile failed checks. When scanning file no errors are shown.

**To Reproduce**
Create Dockerfile in directory `test` with content:
```
FROM debian:buster

ENV CHECKOV_VERSION 1.0.775

RUN export DEBIAN_FRONTEND=noninteractive && \
  apt-get -y update && \
  apt-get -y --no-install-recommends install wget unzip ca-certificates git python3 python3-pip python3-setuptools python3-wheel && \
  pip3 install -U checkov=="${CHECKOV_VERSION}"
```

`checkov -f test/Dockerfile` won't show errors
`checkov -d test` will show error

**Expected behavior**
Show error in both cases.

**Screenshots**
<img width="892" alt="Screenshot 2021-04-10 at 09 39 21" src="https://user-images.githubusercontent.com/672767/114262507-a54dde80-99e0-11eb-9e9e-3e3f5d2d2a7f.png">

**Desktop (please complete the following information):**
 - OS: MacOS 11.2.3
 - Python: 3.9.4
 - Checkov Version 2.0.27


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `checkov/dockerfile/runner.py`
Content:
```
1 import logging
2 import os
3 from dockerfile_parse.constants import DOCKERFILE_FILENAME
4 
5 from checkov.common.output.record import Record
6 from checkov.common.output.report import Report
7 from checkov.common.runners.base_runner import BaseRunner, filter_ignored_directories
8 from checkov.dockerfile.parser import parse, collect_skipped_checks
9 from checkov.dockerfile.registry import registry
10 from checkov.runner_filter import RunnerFilter
11 
12 DOCKER_FILE_MASK = [DOCKERFILE_FILENAME]
13 
14 
15 class Runner(BaseRunner):
16     check_type = "dockerfile"
17 
18     def run(self, root_folder, external_checks_dir=None, files=None, runner_filter=RunnerFilter(),
19             collect_skip_comments=True):
20         report = Report(self.check_type)
21         definitions = {}
22         definitions_raw = {}
23         parsing_errors = {}
24         files_list = []
25         if external_checks_dir:
26             for directory in external_checks_dir:
27                 registry.load_external_checks(directory)
28 
29         if files:
30             for file in files:
31                 if file in DOCKER_FILE_MASK:
32                     (definitions[file], definitions_raw[file]) = parse(file)
33 
34         if root_folder:
35             for root, d_names, f_names in os.walk(root_folder):
36                 filter_ignored_directories(d_names)
37                 for file in f_names:
38                     if file in DOCKER_FILE_MASK:
39                         files_list.append(os.path.join(root, file))
40 
41             for file in files_list:
42                 relative_file_path = f'/{os.path.relpath(file, os.path.commonprefix((root_folder, file)))}'
43                 try:
44                     (definitions[relative_file_path], definitions_raw[relative_file_path]) = parse(file)
45                 except TypeError:
46                     logging.info(f'Dockerfile skipping {file} as it is not a valid dockerfile template')
47 
48         for docker_file_path in definitions.keys():
49 
50             # There are a few cases here. If -f was used, there could be a leading / because it's an absolute path,
51             # or there will be no leading slash; root_folder will always be none.
52             # If -d is used, root_folder will be the value given, and -f will start with a / (hardcoded above).
53             # The goal here is simply to get a valid path to the file (which docker_file_path does not always give).
54             if docker_file_path[0] == '/':
55                 path_to_convert = (root_folder + docker_file_path) if root_folder else docker_file_path
56             else:
57                 path_to_convert = (os.path.join(root_folder, docker_file_path)) if root_folder else docker_file_path
58 
59             file_abs_path = os.path.abspath(path_to_convert)
60             skipped_checks = collect_skipped_checks(definitions[docker_file_path])
61             instructions = definitions[docker_file_path]
62 
63             results = registry.scan(docker_file_path, instructions, skipped_checks,
64                                     runner_filter)
65             for check, check_result in results.items():
66                 result_configuration = check_result['results_configuration']
67                 startline = 0
68                 endline = 0
69                 result_instruction = ""
70                 if result_configuration:
71                     startline = result_configuration['startline']
72                     endline = result_configuration['endline']
73                     result_instruction = result_configuration["instruction"]
74 
75                 codeblock = []
76                 self.calc_record_codeblock(codeblock, definitions_raw, docker_file_path, endline, startline)
77                 record = Record(check_id=check.id, check_name=check.name, check_result=check_result,
78                                 code_block=codeblock,
79                                 file_path=docker_file_path,
80                                 file_line_range=[startline,
81                                                  endline],
82                                 resource="{}.{}".format(docker_file_path,
83                                                         result_instruction,
84                                                         startline),
85                                 evaluations=None, check_class=check.__class__.__module__,
86                                 file_abs_path=file_abs_path, entity_tags=None)
87                 report.add_record(record=record)
88 
89         return report
90 
91 
92     def calc_record_codeblock(self, codeblock, definitions_raw, docker_file_path, endline, startline):
93         for line in range(startline, endline + 1):
94             codeblock.append((line, definitions_raw[docker_file_path][line]))
95
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/checkov/dockerfile/runner.py b/checkov/dockerfile/runner.py
--- a/checkov/dockerfile/runner.py
+++ b/checkov/dockerfile/runner.py
@@ -15,7 +15,7 @@
 class Runner(BaseRunner):
     check_type = "dockerfile"
 
-    def run(self, root_folder, external_checks_dir=None, files=None, runner_filter=RunnerFilter(),
+    def run(self, root_folder=None, external_checks_dir=None, files=None, runner_filter=RunnerFilter(),
             collect_skip_comments=True):
         report = Report(self.check_type)
         definitions = {}
@@ -28,7 +28,7 @@
 
         if files:
             for file in files:
-                if file in DOCKER_FILE_MASK:
+                if os.path.basename(file) in DOCKER_FILE_MASK:
                     (definitions[file], definitions_raw[file]) = parse(file)
 
         if root_folder:

{"golden_diff": "diff --git a/checkov/dockerfile/runner.py b/checkov/dockerfile/runner.py\n--- a/checkov/dockerfile/runner.py\n+++ b/checkov/dockerfile/runner.py\n@@ -15,7 +15,7 @@\n class Runner(BaseRunner):\n     check_type = \"dockerfile\"\n \n-    def run(self, root_folder, external_checks_dir=None, files=None, runner_filter=RunnerFilter(),\n+    def run(self, root_folder=None, external_checks_dir=None, files=None, runner_filter=RunnerFilter(),\n             collect_skip_comments=True):\n         report = Report(self.check_type)\n         definitions = {}\n@@ -28,7 +28,7 @@\n \n         if files:\n             for file in files:\n-                if file in DOCKER_FILE_MASK:\n+                if os.path.basename(file) in DOCKER_FILE_MASK:\n                     (definitions[file], definitions_raw[file]) = parse(file)\n \n         if root_folder:\n", "issue": "Dockerfile scan fails when in directory and used -f\n**Describe the bug**\r\nWhen running directory scan checkov shows Dockerfile failed checks. When scanning file no errors are shown.\r\n\r\n**To Reproduce**\r\nCreate Dockerfile in directory `test` with content:\r\n```\r\nFROM debian:buster\r\n\r\nENV CHECKOV_VERSION 1.0.775\r\n\r\nRUN export DEBIAN_FRONTEND=noninteractive && \\\r\n  apt-get -y update && \\\r\n  apt-get -y --no-install-recommends install wget unzip ca-certificates git python3 python3-pip python3-setuptools python3-wheel && \\\r\n  pip3 install -U checkov==\"${CHECKOV_VERSION}\"\r\n```\r\n\r\n`checkov -f test/Dockerfile` won't show errors\r\n`checkov -d test` will show error\r\n\r\n**Expected behavior**\r\nShow error in both cases.\r\n\r\n**Screenshots**\r\n<img width=\"892\" alt=\"Screenshot 2021-04-10 at 09 39 21\" src=\"https://user-images.githubusercontent.com/672767/114262507-a54dde80-99e0-11eb-9e9e-3e3f5d2d2a7f.png\">\r\n\r\n**Desktop (please complete the following information):**\r\n - OS: MacOS 11.2.3\r\n - Python: 3.9.4\r\n - Checkov Version 2.0.27\r\n\n", "before_files": [{"content": "import logging\nimport os\nfrom dockerfile_parse.constants import DOCKERFILE_FILENAME\n\nfrom checkov.common.output.record import Record\nfrom checkov.common.output.report import Report\nfrom checkov.common.runners.base_runner import BaseRunner, filter_ignored_directories\nfrom checkov.dockerfile.parser import parse, collect_skipped_checks\nfrom checkov.dockerfile.registry import registry\nfrom checkov.runner_filter import RunnerFilter\n\nDOCKER_FILE_MASK = [DOCKERFILE_FILENAME]\n\n\nclass Runner(BaseRunner):\n    check_type = \"dockerfile\"\n\n    def run(self, root_folder, external_checks_dir=None, files=None, runner_filter=RunnerFilter(),\n            collect_skip_comments=True):\n        report = Report(self.check_type)\n        definitions = {}\n        definitions_raw = {}\n        parsing_errors = {}\n        files_list = []\n        if external_checks_dir:\n            for directory in external_checks_dir:\n                registry.load_external_checks(directory)\n\n        if files:\n            for file in files:\n                if file in DOCKER_FILE_MASK:\n                    (definitions[file], definitions_raw[file]) = parse(file)\n\n        if root_folder:\n            for root, d_names, f_names in os.walk(root_folder):\n                filter_ignored_directories(d_names)\n                for file in f_names:\n                    if file in DOCKER_FILE_MASK:\n                        files_list.append(os.path.join(root, file))\n\n            for file in files_list:\n                relative_file_path = f'/{os.path.relpath(file, os.path.commonprefix((root_folder, file)))}'\n                try:\n                    (definitions[relative_file_path], definitions_raw[relative_file_path]) = parse(file)\n                except TypeError:\n                    logging.info(f'Dockerfile skipping {file} as it is not a valid dockerfile template')\n\n        for docker_file_path in definitions.keys():\n\n            # There are a few cases here. If -f was used, there could be a leading / because it's an absolute path,\n            # or there will be no leading slash; root_folder will always be none.\n            # If -d is used, root_folder will be the value given, and -f will start with a / (hardcoded above).\n            # The goal here is simply to get a valid path to the file (which docker_file_path does not always give).\n            if docker_file_path[0] == '/':\n                path_to_convert = (root_folder + docker_file_path) if root_folder else docker_file_path\n            else:\n                path_to_convert = (os.path.join(root_folder, docker_file_path)) if root_folder else docker_file_path\n\n            file_abs_path = os.path.abspath(path_to_convert)\n            skipped_checks = collect_skipped_checks(definitions[docker_file_path])\n            instructions = definitions[docker_file_path]\n\n            results = registry.scan(docker_file_path, instructions, skipped_checks,\n                                    runner_filter)\n            for check, check_result in results.items():\n                result_configuration = check_result['results_configuration']\n                startline = 0\n                endline = 0\n                result_instruction = \"\"\n                if result_configuration:\n                    startline = result_configuration['startline']\n                    endline = result_configuration['endline']\n                    result_instruction = result_configuration[\"instruction\"]\n\n                codeblock = []\n                self.calc_record_codeblock(codeblock, definitions_raw, docker_file_path, endline, startline)\n                record = Record(check_id=check.id, check_name=check.name, check_result=check_result,\n                                code_block=codeblock,\n                                file_path=docker_file_path,\n                                file_line_range=[startline,\n                                                 endline],\n                                resource=\"{}.{}\".format(docker_file_path,\n                                                        result_instruction,\n                                                        startline),\n                                evaluations=None, check_class=check.__class__.__module__,\n                                file_abs_path=file_abs_path, entity_tags=None)\n                report.add_record(record=record)\n\n        return report\n\n\n    def calc_record_codeblock(self, codeblock, definitions_raw, docker_file_path, endline, startline):\n        for line in range(startline, endline + 1):\n            codeblock.append((line, definitions_raw[docker_file_path][line]))\n", "path": "checkov/dockerfile/runner.py"}], "after_files": [{"content": "import logging\nimport os\nfrom dockerfile_parse.constants import DOCKERFILE_FILENAME\n\nfrom checkov.common.output.record import Record\nfrom checkov.common.output.report import Report\nfrom checkov.common.runners.base_runner import BaseRunner, filter_ignored_directories\nfrom checkov.dockerfile.parser import parse, collect_skipped_checks\nfrom checkov.dockerfile.registry import registry\nfrom checkov.runner_filter import RunnerFilter\n\nDOCKER_FILE_MASK = [DOCKERFILE_FILENAME]\n\n\nclass Runner(BaseRunner):\n    check_type = \"dockerfile\"\n\n    def run(self, root_folder=None, external_checks_dir=None, files=None, runner_filter=RunnerFilter(),\n            collect_skip_comments=True):\n        report = Report(self.check_type)\n        definitions = {}\n        definitions_raw = {}\n        parsing_errors = {}\n        files_list = []\n        if external_checks_dir:\n            for directory in external_checks_dir:\n                registry.load_external_checks(directory)\n\n        if files:\n            for file in files:\n                if os.path.basename(file) in DOCKER_FILE_MASK:\n                    (definitions[file], definitions_raw[file]) = parse(file)\n\n        if root_folder:\n            for root, d_names, f_names in os.walk(root_folder):\n                filter_ignored_directories(d_names)\n                for file in f_names:\n                    if file in DOCKER_FILE_MASK:\n                        files_list.append(os.path.join(root, file))\n\n            for file in files_list:\n                relative_file_path = f'/{os.path.relpath(file, os.path.commonprefix((root_folder, file)))}'\n                try:\n                    (definitions[relative_file_path], definitions_raw[relative_file_path]) = parse(file)\n                except TypeError:\n                    logging.info(f'Dockerfile skipping {file} as it is not a valid dockerfile template')\n\n        for docker_file_path in definitions.keys():\n\n            # There are a few cases here. If -f was used, there could be a leading / because it's an absolute path,\n            # or there will be no leading slash; root_folder will always be none.\n            # If -d is used, root_folder will be the value given, and -f will start with a / (hardcoded above).\n            # The goal here is simply to get a valid path to the file (which docker_file_path does not always give).\n            if docker_file_path[0] == '/':\n                path_to_convert = (root_folder + docker_file_path) if root_folder else docker_file_path\n            else:\n                path_to_convert = (os.path.join(root_folder, docker_file_path)) if root_folder else docker_file_path\n\n            file_abs_path = os.path.abspath(path_to_convert)\n            skipped_checks = collect_skipped_checks(definitions[docker_file_path])\n            instructions = definitions[docker_file_path]\n\n            results = registry.scan(docker_file_path, instructions, skipped_checks,\n                                    runner_filter)\n            for check, check_result in results.items():\n                result_configuration = check_result['results_configuration']\n                startline = 0\n                endline = 0\n                result_instruction = \"\"\n                if result_configuration:\n                    startline = result_configuration['startline']\n                    endline = result_configuration['endline']\n                    result_instruction = result_configuration[\"instruction\"]\n\n                codeblock = []\n                self.calc_record_codeblock(codeblock, definitions_raw, docker_file_path, endline, startline)\n                record = Record(check_id=check.id, check_name=check.name, check_result=check_result,\n                                code_block=codeblock,\n                                file_path=docker_file_path,\n                                file_line_range=[startline,\n                                                 endline],\n                                resource=\"{}.{}\".format(docker_file_path,\n                                                        result_instruction,\n                                                        startline),\n                                evaluations=None, check_class=check.__class__.__module__,\n                                file_abs_path=file_abs_path, entity_tags=None)\n                report.add_record(record=record)\n\n        return report\n\n\n    def calc_record_codeblock(self, codeblock, definitions_raw, docker_file_path, endline, startline):\n        for line in range(startline, endline + 1):\n            codeblock.append((line, definitions_raw[docker_file_path][line]))\n", "path": "checkov/dockerfile/runner.py"}]}