DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Docker Images and Containers

Docker Images and Containers

Learn more about Docker images and containers.

Manjula Jayawardana user avatar by
Manjula Jayawardana
·
Jul. 03, 19 · Tutorial
Like (9)
Save
Tweet
Share
20.36K Views

Join the DZone community and get the full member experience.

Join For Free

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.

docker image to containers

Docker Image

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.

Docker Container

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.

How to Download an Image

We can download a Docker image using 2 methods.

  • pull — we can use pull command to get an image
$ docker container run nginx 
  • create a container — when we create a container from an image, it downloads the image from the repository if it is not available in the host.

Docker Command Structure

There are many commands in docker. So Docker has grouped them together into a common format.

docker COMMAND SUBCOMMAND
$ docker container ls 

Useful Docker Commands

  • docker image ls — list available images
  • docker image rm — remove an image
  • docker image inspect — inspect an image
  • docker container run — run a container
  • docker container ls — list containers
  • docker container stop — stop a running container

Dry Run

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 

How to Stop a Container

 $ docker container stop my-nginx 

Verify whether it is running by using ls command.

$ docker container ls
$ docker container ls -a 

Starting a Stopped Container

 $ docker container start my-nginx 

Removing the Container

First stop the running container. Then use remove command to remove it.

$ docker container stop my-nginx
$ docker container remove my-nginx

Removing the Image

 $ docker image remove nginx 

That's all for now :)

Docker (software)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Top Five Tools for AI-based Test Automation
  • Silver Bullet or False Panacea? 3 Questions for Data Contracts
  • The Real Democratization of AI, and Why It Has to Be Closely Monitored
  • DevSecOps Benefits and Challenges

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: