Docker create Command
docker createThis command is used to create a new container, but will not start it.
docker createThe command creates a container instance based on the specified image and parameters, but the container is only initialized at creation time and does not execute any processes.
Same usage asdocker run。
Syntax
docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
Common Parameters
--name: Specify a name for the container.-p, --publish: Port mapping, format ishost_port:container_port。-v, --volume: Mount volume, format ishost_dir:container_dir。-e, --env: Set environment variables.--network: Specify the network mode of the container.--restart: Container restart policy (e.g.,no、on-failure、always、unless-stopped)。-u, --userSpecify the user.--entrypoint: Override the container's default entry point.--detach: Create the container in the background.
Example
Create a container:
docker create ubuntu
Create a container based on the ubuntu image, but do not start it.
Create and specify a container name:
docker create --name my_container ubuntu
Create a container named my_container, but do not start it.
Create and set environment variables:
docker create -e MY_ENV_VAR=my_value ubuntu
Create a container and set the environment variable MY_ENV_VAR to the value my_value.
Create and mount a volume:
docker create -v /host/data:/container/data ubuntu
Create a container and mount the host's /host/data directory to the container's /container/data directory.
Create with port mapping:
docker create -p 8080:80 nginx
Create a container, mapping the local host's port 8080 to the container's port 80, but do not start it.
Create and specify restart policy:
docker create --restart always nginx
Create a container and set the restart policy to always.
Create and specify user:
docker create -u user123 ubuntu
Create a container and run it as user123.
View containers
After creating a container, you can use the docker ps -a command to view all containers, including those that have been created but not started.
docker ps -a
Start the created container
Use the docker start command to start a container that has been created but not started:
docker start my_container
Summary
docker create: Used to create a new container instance without starting it. The container's configuration can be set through various parameters.docker start: Start the created container so that it begins running.
docker createThis command allows users to pre-configure container settings and manually start the container when needed, which is particularly useful for automated deployment and testing scenarios.
other extensions