Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Docker create command

Docker create command

Docker Command ReferenceDocker Command Reference


docker create The command creates a new container but does not start it.

docker create The command creates a container instance based on the specified image and arguments, but the container is only initialized at creation and does not execute any process.

Usage is the same as docker run。

Syntax

docker create [OPTIONS] IMAGE [COMMAND] [ARG...]

Common parameters

Example

Create a container:



docker create ubuntu

Creates a container from the ubuntu image but does not start it.

Create and specify a container name:



docker create --name my_container ubuntu

Creates a container named my_container but does not start it.

Create and set environment variables:



docker create -e MY_ENV_VAR=my_value ubuntu

Creates a container and sets the environment variable MY_ENV_VAR to my_value.

Create and mount a volume:



docker create -v /host/data:/container/data ubuntu

Creates a container and mounts the host's /host/data directory to the container's /container/data directory.

Create with port mapping:



docker create -p 8080:80 nginx

Creates a container and maps local host port 8080 to container port 80, but does not start it.

Create and specify a restart policy:



docker create --restart always nginx

Creates a container and sets its restart policy to always.

Create and specify a user:



docker create -u user123 ubuntu

Creates a container and runs it as user user123.

View containers

After creating a container, you can use the docker ps -a command to view all containers, including those created but not started.



docker ps -a

Start a created container

Use the docker start command to start a created but unstarted container:



docker start my_container

Summary

docker create The command allows users to preconfigure container settings and manually start the container when needed, which is particularly useful for automated deployment and testing scenarios.


Docker Command ReferenceDocker Command Reference