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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • How To Use the Node Docker Official Image
  • Using Environment Variable With Angular
  • How to Integrate a Distributed Database With Event Streaming
  • Deploy an Application for Azure Container Registry

Trending

  • How Can Developers Drive Innovation by Combining IoT and AI?
  • Customer 360: Fraud Detection in Fintech With PySpark and ML
  • Understanding IEEE 802.11(Wi-Fi) Encryption and Authentication: Write Your Own Custom Packet Sniffer
  • AI-Driven Root Cause Analysis in SRE: Enhancing Incident Resolution
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Docker Commands Beginners Should Know

Docker Commands Beginners Should Know

This tutorial reviews basic Docker commands for a new user.

By 
Eric Goebelbecker user avatar
Eric Goebelbecker
DZone Core CORE ·
Aug. 17, 22 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
14.1K Views

Join the DZone community and get the full member experience.

Join For Free

Docker is an open-source platform for creating, deploying, and running containers. It's available for macOS, Windows, and Linux, and enjoys wide support from all the major cloud providers. So, you can create your containers on your favorite operating system and deploy them anywhere.

Let's look at the Docker commands you need to know to manage Docker images and containers.

List Running Containers With docker ps

First, seeing what Docker is doing is a good place to start, so let's open with getting a list of running containers. You do this with docker ps:

This system has three running containers. Docker shows you their IDs, names, status, and a few more useful statistics. If you look at the fifth column, you'll see that all the containers are "up."

Let's add the -a argument to docker ps and see if there is a difference:

This command line option added another container to the list, and its status is exited. The -a argument means "all," including containers that are stopped or exited.

Run Containers With docker run

Listing containers is great, but running them is even more fun.

Let's start with a shell running in an Ubuntu container. For this, we use docker run:

We used three sets of command line arguments to start this shell:

  • -it combines i for interactive and t for creating a pseudo-terminal for the shell.
  • --name ubuntu_shell assigns a name to the container, instead of one chosen from random.
  • ubuntu is the name of the image we want Docker to run.

If you don't tell Docker what to name your containers, you'll get a combination of random words. Specifying a name makes it much easier to keep track of what's running.

Docker run has an enormous set of command-line options. Let's look at one more variation before moving on.

Let's run nginx:

We started this container with a different set of command line arguments:

  • -d puts the container in the background. This makes sense with a web server.
  • --name nginx names the container nginx.
  • -p 8080:80 tells Docker to redirect input to port 8080 on the host to port 80 for the container.
  • nginx is the image we want Docker to start for this container.

After starting the container, docker ps -a shows it running, with the port mappings.

Let's retrieve a page from the new web server.

There it is! The web server responds to a request on port 8080.

Stop and Remove Containers

What happens when we exit the Ubuntu shell?

The container transitioned from running to exited, but it's still there.

We need to remove it:

docker rm with the container name removes it from memory. This is a reason to explicitly name your containers: It's easier to figure out what's running and what's stopped.

How do we stop the web server, though? 

docker stop with the container name will stop it. Then you still need to use rm to remove it.

Docker Statistics

Finally, let's look at the resources our containers are using with docker stats:

docker stats shows you how much memory, CPU, and I/O your containers are consuming. It refreshes every few seconds until you quit out of it, so it's a great tool for keeping an eye on a container while you're testing it.

Basic Docker Commands

Getting started with Docker is easy. You can start, stop, remove, and watch your containers with a few simple commands. Get started with containers today!

Command (computing) Docker (software)

Opinions expressed by DZone contributors are their own.

Related

  • How To Use the Node Docker Official Image
  • Using Environment Variable With Angular
  • How to Integrate a Distributed Database With Event Streaming
  • Deploy an Application for Azure Container Registry

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!