Every docker image contains some necessary sets of files. These files are nothing but a small part of an operating system that is required to run docker container as an isolated unit of any machine. So, you can say this part is a minimal part of an operating system or operating system userspace minus operating system kernel.
In this tutorial, we will show you how to use docker run image command in Linux.
Requirements
- A Linux system with Docker installed.
- A root password is configured in your system.
Basic Syntax
Docker image is a read-only template, composed of a layered file system, needed to build a running docker container.
The basic syntax of docker images command is shown below:
A brief explanation of each option is shown below:
build: This option is used to build an image from the docker file.
pull: This option is used to download an image from the docker registry.
push: This option is used to upload or push an image to the docker registry.
save: This option is used to save an image to the tar archive.
prune: This option is used to remove all unused images.
rm: This option is used to remove one or more images.
history: This option is used to display the history of an image.
load: This option is used to load an image from the tar archive.
Download Docker Image
You can download and run any image from the Docker Hub using the following syntax:
For example, to download an Nginx image from the Docker Hub run the following command:
This will download the Nginx image, as shown below:
latest: Pulling from library/nginx
8559a31e96f4: Pull complete
8d69e59170f7: Pull complete
3f9f1ec1d262: Pull complete
d1f5ff4f210d: Pull complete
1e22bfa8652e: Pull complete
Digest: sha256:21f32f6c08406306d822a0e6e8b7dc81f53f336570e852e25fbe1e3e3d0d0133
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
Now, you can run the downloaded image in the container with the following command:
This will start the Nginx container and map TCP port 80 in the container to port 8080 on the Docker host:
You can see your running container with the following command:
You should see the following output:
ba43241e3ce3 nginx "/docker-entrypoint.…" 2 minutes ago, Up 2 minutes 0.0.0.0:8080->80/tcp frosty_bassi
List Docker Image
You can list all the images available in your system with the following command:
Or
You should see the following output:
nginx latest 2622e6cca7eb 4 weeks ago 132MB
You can also use the option -q to display only image ID of the images:
You should see the following output:
Conclusion
In the above guide, you learned what docker image is and how to download and run images from the Docker Hub. You can use this guide to learn the basics of the Docker image.
from Linux Hint https://ift.tt/3eYWArJ
0 Comments