Table: dockerfile_instruction - Query Docker Dockerfile Instructions using SQL
Dockerfile Instructions are the commands that are used in a Dockerfile to build a Docker image. These instructions specify what to include in the Docker image and how it should behave when it is run. They are the building blocks of Docker images, specifying everything from the base image to use, to the commands to run, to the metadata to include.
Table Usage Guide
The dockerfile_instruction
table provides insights into the instructions used within Dockerfiles in Docker. As a DevOps engineer, explore instruction-specific details through this table, including the instruction type, arguments, and associated metadata. Utilize it to uncover information about instructions, such as what base images are used, the commands that are run, and the metadata that is included.
Examples
List instructions in a specific Dockerfile
Explore the sequence of instructions within a specific Dockerfile to better understand the build process and dependencies. This could be beneficial in assessing the complexity of the build, identifying potential areas for optimization, or troubleshooting issues.
Set the path
column to query a specific Dockerfile. A full path must be provided.
select *from dockerfile_instructionwhere path = '/full/path/to/Dockerfile'order by start_line;
select *from dockerfile_instructionwhere path = '/full/path/to/Dockerfile'order by start_line;
List all Dockerfiles matched in the paths config
Explore all Dockerfile instructions sorted by their respective paths and starting lines. This can help you understand the structure and organization of your Dockerfiles, making it easier to manage and troubleshoot your Docker environment.
The paths
config parameter sets directories (including wildcards) to search
for Dockerfiles. To match, either the filename is Dockerfile
(e.g.
Dockerfile
, Dockerfile.example
), or the extension is .dockerfile
(e.g.
nginx.dockerfile
).
select *from dockerfile_instructionorder by path, start_line;
select *from dockerfile_instructionorder by path, start_line;
List base images
Explore the foundational elements of your Docker environment by identifying the base images used in your Dockerfiles. This can aid in understanding dependencies, ensuring consistency, and managing potential security vulnerabilities across your projects.
select path, start_line, data ->> 'image' as image, data ->> 'tag' as tagfrom dockerfile_instruction as cmdwhere cmd.cmd = 'from'order by path, start_line, image, tag;
select path, start_line, json_extract(data, '$.image') as image, json_extract(data, '$.tag') as tagfrom dockerfile_instruction as cmdwhere cmd.cmd = 'from'order by path, start_line, image, tag;
Find all exposed ports
Identify instances where certain ports are exposed in your Dockerfile instructions. This can help you manage and secure your network traffic by understanding which ports are open.
select path, start_line, (p ->> 'port') :: int as port, p ->> 'protocol' as protocolfrom dockerfile_instruction as cmd, jsonb_array_elements(data) as pwhere cmd.cmd = 'expose'order by path, start_line, port, protocol;
select path, start_line, cast(json_extract(p.value, '$.port') as integer) as port, json_extract(p.value, '$.protocol') as protocolfrom dockerfile_instruction as cmd, json_each(cmd.data) as pwhere cmd.cmd = 'expose'order by path, start_line, port, protocol;
Schema for dockerfile_instruction
Name | Type | Operators | Description |
---|---|---|---|
_ctx | jsonb | Steampipe context in JSON form. | |
args | jsonb | Array of arguments passed to the command. | |
data | jsonb | Command data, parsed into a convenient format for each command type. | |
end_line | bigint | Last line number of this cmd in the file. | |
flags | jsonb | Flags passed to the command. | |
instruction | text | Command name in lowercase form, e.g. from, env, run, etc. | |
path | text | = | Full path of the file. |
prev_comment | jsonb | Comment above the command in the Dockerfile. | |
source | text | Full original source code of the cmd. | |
sp_connection_name | text | =, !=, ~~, ~~*, !~~, !~~* | Steampipe connection name. |
sp_ctx | jsonb | Steampipe context in JSON form. | |
stage | text | Stage name in the Dockerfile, defaults to the stage number. | |
stage_number | bigint | Stage number in the Dockerfile, starting at zero. | |
start_line | bigint | First line number of this cmd in the file. | |
sub_instruction | text | Sub command name in lowercase form, e.g. set to 'run' for 'onbuild run ...'. |
Export
This table is available as a standalone Exporter CLI. Steampipe exporters are stand-alone binaries that allow you to extract data using Steampipe plugins without a database.
You can download the tarball for your platform from the Releases page, but it is simplest to install them with the steampipe_export_installer.sh
script:
/bin/sh -c "$(curl -fsSL https://steampipe.io/install/export.sh)" -- docker
You can pass the configuration to the command with the --config
argument:
steampipe_export_docker --config '<your_config>' dockerfile_instruction