YouTip LogoYouTip

Docker Create Command

# Docker create Command [![Image 3: Docker Command Manual](#)Docker Command Manual](#) * * * The `docker create` command is used to create a new container but does not start it. The `docker create` command creates a container instance based on the specified image and parameters, but the container is only initialized upon creation and does not execute any processes. Its usage is similar to (#). ### Syntax docker create IMAGE [ARG...] ### Common Parameters * **`--name`**: Assigns a name to the container. * **`-p, --publish`**: Port mapping, in the format `host_port:container_port`. * **`-v, --volume`**: Mounts a volume, in the format `host_dir:container_dir`. * **`-e, --env`**: Sets environment variables. * **`--network`**: Specifies the network mode for the container. * **`--restart`**: Restart policy for the container (e.g., `no`, `on-failure`, `always`, `unless-stopped`). * **`-u, --user`**: Specifies the user. * **`--entrypoint`**: Overrides the container's default entrypoint. * **`--detach`**: Creates the container in the background. ### Examples Create a container: docker create ubuntu Creates a container based on 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 an environment variable: 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 and map ports: docker create -p 8080:80 nginx Creates a container, mapping port 8080 on the local host to port 80 in the container, but does not start it. Create and specify a restart policy: docker create --restart always nginx Creates a container and sets the restart policy to always. Create and specify a user: docker create -u user123 ubuntu Creates a container and runs it as the user 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 a 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 via various parameters. * **`docker start`**: Starts a created container, making it begin running. The `docker create` 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. * * Docker Command Manual](#)
← Prop Element OffsetleftProp Element Offsetheight β†’