Commands
7 methodsTop-level docker subcommands for container and image lifecycle.
docker run [options] image [command] [args...]Creates a new container from an image and starts it, running the given command.
Parameters
| Name | Type | Description |
|---|---|---|
| options | string | Flags such as -d (detached), -p (port), -v (volume), -e (env). |
| image | string | Image to run. |
| command | string | Optional command overriding the image CMD. |
Returns
ContainerID
Example
docker
docker run -d -p 8080:80 --name web nginx:alpinedocker build [options] path | URLBuilds an image from a Dockerfile in the given path or URL.
Parameters
| Name | Type | Description |
|---|---|---|
| options | string | Flags such as -t (tag), --build-arg, --no-cache, --file. |
| path | string | Build context path or URL. |
Returns
void
Example
docker
docker build -t myapp:1.0 -f Dockerfile.prod .docker pull [options] name[:tag]Downloads an image from a registry and stores it locally.
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | Repository name with optional registry prefix. |
| tag | string | Image tag (defaults to latest). |
Returns
void
Example
docker
docker pull postgres:16docker push [options] name[:tag]Uploads a local image to a registry.
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | Repository name including registry namespace. |
| tag | string | Image tag to push. |
Returns
void
Example
docker
docker push ghcr.io/me/myapp:1.0docker ps [options]Lists containers. By default only running containers are shown.
Parameters
| Name | Type | Description |
|---|---|---|
| options | string | Flags such as -a (all), -q (ids only), --filter. |
Returns
void
Example
docker
docker ps -a --filter "status=exited"docker exec [options] container command [args...]Runs a new command inside a running container.
Parameters
| Name | Type | Description |
|---|---|---|
| options | string | Flags such as -i (stdin), -t (tty), -u (user). |
| container | string | Container name or id. |
| command | string | Command to execute. |
Returns
void
Example
docker
docker exec -it web shdocker logs [options] containerPrints the stdout/stderr logs of a container.
Parameters
| Name | Type | Description |
|---|---|---|
| options | string | Flags such as -f (follow), --tail, --since, -t (timestamps). |
| container | string | Container name or id. |
Returns
void
Example
docker
docker logs -f --tail 100 web