Linux command
docker-container-run 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Run a container
docker container run [image]
Run interactively
docker container run -it [image] /bin/bash
Run in background
docker container run -d [image]
Run with port mapping
docker container run -p [8080:80] [image]
Run with volume mount
docker container run -v [/host/path:/container/path] [image]
Run with name
docker container run --name [mycontainer] [image]
Run and remove on exit
docker container run --rm [image]
Run with environment variable
docker container run -e [VAR=value] [image]
说明
docker container run creates and starts a new container from a specified image, combining the functionality of docker container create and docker container start into a single command. This is the most common way to launch containers in Docker. When executed, Docker pulls the image if not locally available, creates a container with the specified configuration, and starts it. The command supports extensive configuration options for networking, storage, resource limits, and runtime behavior. Using --rm ensures ephemeral containers are cleaned up automatically, while -d enables daemon mode for background services. This command is equivalent to the legacy docker run command.
参数
- -d, --detach
- Run in background.
- -i, --interactive
- Keep STDIN open.
- -t, --tty
- Allocate pseudo-TTY.
- -p, --publish _hostPort:containerPort_
- Publish port.
- -v, --volume _src:dest_
- Bind mount a volume.
- -e, --env _var=value_
- Set environment variable.
- --name _name_
- Assign container name.
- --rm
- Remove container on exit.
- --network _network_
- Connect to the specified network (bridge, host, none, or a user-defined network).
- -w, --workdir _dir_
- Working directory inside the container.
- -u, --user _user__:group_
- Username/UID (and optionally group/GID) to run as.
- --entrypoint _cmd_
- Override the image's default ENTRYPOINT.
- --restart _policy_
- Restart policy: no, on-failure:_N_, always, or unless-stopped.
- --pull _policy_
- Pull policy before running: always, missing (default), or never.
- -m, --memory _bytes_
- Hard memory limit (e.g. _512m_, _2g_).
- --cpus _n_
- Number of CPUs the container may use (e.g. 1.5).
- --hostname _name_
- Hostname assigned inside the container.
- --privileged
- Grant extended privileges to the container.
- --read-only
- Mount the container's root filesystem read-only.
- --platform _os/arch_
- Set the platform for the image (e.g. linux/amd64).
FAQ
What is the docker-container-run command used for?
docker container run creates and starts a new container from a specified image, combining the functionality of docker container create and docker container start into a single command. This is the most common way to launch containers in Docker. When executed, Docker pulls the image if not locally available, creates a container with the specified configuration, and starts it. The command supports extensive configuration options for networking, storage, resource limits, and runtime behavior. Using --rm ensures ephemeral containers are cleaned up automatically, while -d enables daemon mode for background services. This command is equivalent to the legacy docker run command.
How do I run a basic docker-container-run example?
Run `docker container run [image]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -d, --detach do in docker-container-run?
Run in background.