ToolXON Blog

Docker Commands

Docker commands: A hands-on Docker guide for checking the engine, creating containers, listing workloads, reading logs and running commands inside a container. This guide explains what each command does, its syntax, practical examples, useful options, and common mistakes. Commands are shown for typical installations; flags can vary across operating-system and tool versions.

Before you start

Open a terminal appropriate for the operating system shown in the examples. Check that the required tool is installed and that you are running it with the permissions needed for your task. Replace sample names, paths, hostnames and IDs with values from your own environment.

Syntax at a glance

Square brackets usually indicate optional arguments, while uppercase words such as FILE, HOST and PACKAGE are placeholders that you replace. Keep quotes around paths or text that contains spaces. Commands should be tested on a safe sample before being used in production.

Quick command reference

CommandWhat it doesExampleUseful options
docker versionDisplay client and server version detailsdocker versiondocker info shows engine configuration
docker runCreate and start a container from an imagedocker run --rm hello-world-d runs in background; -p maps ports; --rm removes the container on exit
docker psList running containersdocker ps -a-a includes stopped containers; --format changes output
docker logsRead a container’s standard output and errordocker logs --tail 100 -f web-app--tail N limits lines; -f follows new output
docker execRun a command in a running containerdocker exec -it web-app sh-i keeps stdin open; -t allocates a terminal

Command syntax and examples explained

1. docker version

Purpose: Display client and server version details.

Syntax

docker version

Example

docker version

Options and notes: docker info shows engine configuration.

A client/server mismatch may explain features missing from a local setup.

2. docker run

Purpose: Create and start a container from an image.

Syntax

docker run [OPTIONS] IMAGE

Example

docker run --rm hello-world

Options and notes: -d runs in background; -p maps ports; --rm removes the container on exit.

Avoid running untrusted images or granting them privileged access.

3. docker ps

Purpose: List running containers.

Syntax

docker ps [OPTIONS]

Example

docker ps -a

Options and notes: -a includes stopped containers; --format changes output.

Container names and IDs are accepted by many later Docker commands.

4. docker logs

Purpose: Read a container’s standard output and error.

Syntax

docker logs CONTAINER

Example

docker logs --tail 100 -f web-app

Options and notes: --tail N limits lines; -f follows new output.

Logs may contain secrets; review before sharing them.

5. docker exec

Purpose: Run a command in a running container.

Syntax

docker exec [OPTIONS] CONTAINER COMMAND

Example

docker exec -it web-app sh

Options and notes: -i keeps stdin open; -t allocates a terminal.

The container must be running and include the requested shell or program.

Common mistakes and troubleshooting

  • Command not found: confirm the tool is installed and available on your PATH; open a new terminal after changing PATH.
  • Permission denied: verify the current account, file permissions and target path. Use administrator/root privileges only when genuinely required.
  • Unexpected output: check the command version, quoting, current directory and exact arguments. Consult the local help or manual for options supported by your build.
  • Destructive operations: preview the target and keep a backup before deleting data, rewriting history, flashing a partition or changing system configuration.

Safety tips

Review every command before running it, especially commands that delete files, change permissions, flash firmware, alter a database or expose a network service. For network scanning and remote administration, work only on devices and systems you own or are authorized to test. Keep credentials, private keys, access tokens and log files private.

Frequently asked questions

Do these commands work on every system?

Not always. Some commands are specific to Windows, Linux, Android, a particular package manager or an installed tool version. Use the syntax shown for your platform and check local help when a flag is unavailable.

Can I copy and run every example exactly?

Use the examples as templates. Replace placeholders such as filenames, package IDs, hostnames and paths with your own values, and verify the effect before executing a command that changes data or system state.

Conclusion

Use this reference as a starting point, then confirm flags in the tool’s official help or manual for your installed version. A clear understanding of syntax, options and side effects makes command-line work more reliable.