FreeKB - docker create - pull an image and create a container
docker create - pull an image and create a container

Home > Search

This assumes you have installed Docker on Linux and Docker is running. Before using the docker create command, you'll want to use the docker images command to return the list of images that are already installed, like this.

docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
foo                 latest              105b54dc64f1        32 hours ago        196.7 MB

 

And the docker ps command to list the containers.

docker ps -a

CONTAINER ID     IMAGE              COMMAND                 CREATED         STATUS     PORTS     NAMES
d937372c09ab9    b939aa938add9913   "/docker-entrypoin..."  6 minutes ago   Created              my-container

 

Then, use the docker search command to find the image you want to install.

Let's say there is no image or container for "bar". The docker create command followed by the name of the image will both pull down the image and create a container. In this example, the "bar" image will be pulled down and the "bar" container will be created. Or, you could use the docker pull command to only pull down the image, but not create a container.

docker create bar

 

By default, the latest version of the image will be pulled down. Or, you can explicity include latest.

docker create bar:latest

 

Something like this should be displayed.

Unable to find image 'bar:latest' locally
Trying to pull repository docker.io/library/bar ...
latest: Pulling from docker.io/library/bar
xxxxxxxxxxxxxx: Pull complete
xxxxxxxxxxxxxx: Pull complete
xxxxxxxxxxxxxx: Pull complete
Digest: sha256:xxxxxxxxxxxxxxxxxxxxxxx
...

 

Reissuing the docker images command should now show that the latest bar image has been pulled down.

docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
foo                 latest              105b54dc64f1        32 hours ago        196.7 MB
bar                 latest              95ga44bc5582        2 weeks ago         967 B

 

The docker ps command should also show the container associated with the image.

docker ps -a

CONTAINER ID     IMAGE              COMMAND                 CREATED         STATUS     PORTS     NAMES
d937372c09ab9    b939aa938add9913   "/docker-entrypoin..."  6 minutes ago   Created              my-container

 


Name

The --name option can be used to give the container associated with the image a certain name. In this example, the container will be named my-container.

docker create --name my-container bar:latest

 

The docker ps command will show the name.

docker ps -a

CONTAINER ID     IMAGE              COMMAND                 CREATED         STATUS     PORTS     NAMES
d937372c09ab9    b939aa938add9913   "/docker-entrypoin..."  6 minutes ago   Created              my-container

 


Networking

The --network option can be used to configure the image to use a docker network, like this.

docker create --network=foo-network bar:latest

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter db24a in the box below so that we can be sure you are a human.




Comments