Learn more about Docker images and containers
When we work with Docker, it is important to have basic knowledge of docker images and containers. Docker containers are created using docker images. We are going to look into basic commands to create docker containers using images.
An image is a read-only template with instructions for creating a Docker container. It is a combination of file system and parameters. Often, an image is based on another image with some additional customization.
We can use existing images or create our own images.
A container is a runnable instance of an image. We can create as many as we want from an image. A container is isolated from the host by default. We can modify its behavior using network, volume, etc.
When a container is created, we can stop, restart, remove it.
We can download a Docker image using 2 methods.
$ docker container run nginx
There are many commands in docker. So Docker has grouped them together into a common format.
docker COMMAND SUBCOMMAND $ docker container ls
Let's test these commands with nginx.
$ docker container run --name my-nginx -p 80:80 nginx $ docker image ls $ docker container ls
Visit localhost in your browser. You should see nginx is running.
We can inspect image and container using inspect command.
$ docker container inspect my-nginx $ docker image inspect nginx
$ docker container stop my-nginx
Verify whether it is running by using ls command.
$ docker container ls $ docker container ls -a
$ docker container start my-nginx
First stop the running container. Then use remove command to remove it.
$ docker container stop my-nginx $ docker container remove my-nginx
$ docker image remove nginx
That's all for now. Thanks for reading
If you liked this post, share it with all of your programming buddies!
Originally published on https://dzone.com
Build your eCommerce project by hiring our expert eCommerce Website developers. Our Dedicated Web Designers develop powerful & robust website in a short span of time.
Best Mobile App Development Company India, WebClues Global is one of the leading web and mobile app development company. Our team offers complete IT solutions including Cross-Platform App Development, CMS & E-Commerce, and UI/UX Design.
Do you want excellent and world class web development services for your valuable projects? Contact **RB Genie **now, we have more than 8 years experienced team of web developers, which specializes in overall web design and website development...