Docker Container Create


This command creates a new container. The initial status of the new container is created.


Difference Between Docker Create And Run

docker run = docker create + docker start 

docker create command creates a writeable container from the image and prepares it for running. docker run command creates the container (same as docker create ) and starts it.


Syntax

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


Examples

Let's create a docker container and run the sleep 60 commands in it-

learning-ocean:~ gaurav docker container create ubuntu:14.04 sleep 60
d67ad7182b19005b66bb48bef543457343883d97ae30dcb8db7c87017ce61d4d
learning-ocean:~ gaurav


Now list all the containers-


learning-ocean:~ gaurav$ docker container ls -a
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS        PORTS            NAMES
d67ad7182b19   ubuntu:14.04   "sleep 60"               33 seconds ago   Created                        festive_rosalind
learning-ocean:~ gaurav

We can see that the container status is created, but it's not yet started.

And at last, start the created container with the below command-


learning-ocean:~ gaurav$ docker container start d6
d6
learning-ocean:~ gaurav$
learning-ocean:~ gaurav$ docker container ls
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS               NAMES
d67ad7182b19   ubuntu:14.04   "sleep 60"               4 minutes ago   Up 3 seconds                       festive_rosalind
learning-ocean:~ gaurav