docker
containerization
CLI
command-line
troubleshooting

Docker: 'docker run' requires at least 1 argument (error fix)

Codemia Knowledge Hub ·

The error "docker container run requires at least 1 argument" means you ran docker container run without an image name. Every run needs an image, placed after all the options: docker container run [OPTIONS] IMAGE [COMMAND].

The command syntax

docker container run (shorthand docker run) creates a container from an image and starts it. The image is the one required argument, because Docker needs to know which filesystem and configuration to base the container on.

bash
docker container run [OPTIONS] IMAGE [COMMAND] [ARG...]
  • IMAGE is required. It names the base image (for example nginx, python:3.12 or ubuntu:22.04).
  • OPTIONS are optional flags and go before the image name.
  • COMMAND and ARG... are optional and override the image's default command.

What causes the error

No image name at all

bash
# This produces the error
docker container run -d -p 8080:80

Docker parses the flags but finds no positional argument for the image. Always put the image name after all options.

Image name before the options

bash
# This will not work as expected
docker container run nginx -d -p 8080:80

Docker takes nginx as the image and -d -p 8080:80 as the command to run inside the container. That fails because the Nginx image has no -d binary. Options must come before the image.

A missing backslash in a multi-line command

With line continuations, a missing backslash makes the shell run a partial command:

bash
1# Broken: missing backslash after -d
2docker container run -d
3  -p 8080:80 \
4  nginx:latest

The shell runs docker container run -d on its own, with no image. Add the backslash after -d so the command continues on the next line:

bash
1# Fixed
2docker container run -d \
3  -p 8080:80 \
4  nginx:latest

Mixing up run and exec

docker container exec runs a command in a container that is already running and needs a container name or ID plus a command. Typing run when you mean exec, or the reverse, gives unexpected errors.

bash
1# Run a command inside an existing container
2docker container exec my-web nginx -t
3
4# Create and start a new container (needs an image)
5docker container run nginx:latest nginx -t

Working examples

A simple container

bash
docker container run ubuntu:22.04 echo "Hello from Ubuntu"

Docker pulls ubuntu:22.04 if it isn't present locally, creates a container, runs echo in it, and exits.

An interactive shell

bash
docker container run -it alpine sh

-i keeps STDIN open and -t allocates a pseudo-TTY, which together give you an interactive shell in the container.

A background service

bash
docker container run -d -p 8080:80 --name my-web nginx:latest

This starts Nginx in detached mode (-d), maps host port 8080 to container port 80, and names the container my-web.

Environment variables

bash
1docker container run -d \
2  -p 5432:5432 \
3  -e POSTGRES_USER=admin \
4  -e POSTGRES_PASSWORD=secret \
5  -e POSTGRES_DB=myapp \
6  postgres:16

Each -e sets an environment variable in the container, the standard way to pass configuration to containerized services.

Other useful flags

bash
1# Mount a volume
2docker container run -v /host/path:/container/path nginx
3
4# Set a restart policy
5docker container run --restart unless-stopped redis
6
7# Limit memory
8docker container run --memory 512m python:3.12 python script.py
9
10# Set the working directory
11docker container run -w /app node:20 npm start
12
13# Remove the container after it exits
14docker container run --rm ubuntu:22.04 date

--rm is especially handy in development and testing: it removes the container when it stops, so exited containers don't pile up.

Checking and managing containers

bash
1# List running containers
2docker container ls
3
4# List all containers including stopped ones
5docker container ls -a
6
7# View container logs
8docker container logs my-web
9
10# Inspect container configuration
11docker container inspect my-web
12
13# Stop a running container
14docker container stop my-web
15
16# Remove a stopped container
17docker container rm my-web
  • docker run and docker container run are aliases, so either works. Don't confuse them with docker create and docker start, which are separate steps.
  • Leaving out the image tag defaults to :latest, which may pull a different version than you expect. Pin image versions in production.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design