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 Video Library
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
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

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • How To Use the Node Docker Official Image
  • Using Environment Variable With Angular
  • Docker Commands Beginners Should Know
  • How to Integrate a Distributed Database With Event Streaming

Trending

  • Snowflake vs. Data Bricks: Compete To Create the Best Cloud Data Platform
  • How To Simplify Multi-Cluster Istio Service Mesh Using Admiral
  • Exploring the Evolution and Impact of Computer Networks
  • Difference Between High-Level and Low-Level Programming Languages
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Docker Command Cheatsheet

Docker Command Cheatsheet

If you're new to Docker or just want to have a list of handy commands, this cheatsheet will help you install, monitor, maintain, and clean up your images and processes.

Akshay Rangnekar user avatar by
Akshay Rangnekar
·
Jan. 03, 17 · Tutorial
Like (45)
Save
Tweet
Share
31.37K Views

Join the DZone community and get the full member experience.

Join For Free

I completed the course on “Docker Quickstart” at LinuxAcademy recently. Throughout the course, I made some notes on the important commands I found myself using over and over again. If you are new to Docker, here are my notes on getting started with the tool.

Installing Docker

All commands as root on CentOs7:

cd /etc/yum.repos.d
vim docker.repo


[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.com/repos/main/centos/7/
enabled=true
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

yum install docker-engin

systemctl enable docker
systemctl start docker

usermod -a -G docker <username>
cat /etc/group | grep docker #should use the <username> as the group for the docker program


Docker Commands

List images:

docker images


List running docker processes:

docker ps


List all processes that were ever run:

docker ps -a


List only the container IDs:

docker ps -a -q


Running processes:

docker run <image>
docker run -d <image> = run in disconnected / daemon mode
docker run --name="Some Name" = name the running instance
docker start <name> = will restart a closed / exited instance of the image
docker exec -it <name> <command> = run a command within a running container without changing the state of the running container
docker stop <name> = stop a running container by using the name


Cleaning up Docker:

docker rm containerid = removes an instance of the container that was run
docker rm `docker ps -a -q` = remove all stopped containers
docker rmi image-name = removes the docker image and its dependencies


Redirect port:

docker run -P = will redirect the container's port to a random port on the host machine's user port (port no 32,000+)
docker run -p 8080:80 = will redirect the container's port 80 to a port 8080 on the host machine's user port 
docker port <container-name> = will list the port mapping information


Adding volume:

using the "-v" option mounts the local file system. eg to mount for an nginx on centos
-v /home/user/www:/usr/share/nginx/html


Building a Docker file:

docker login --username=<username>
Enter password

docker push username/repo


Docker (software) Command (computing)

Published at DZone with permission of Akshay Rangnekar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Use the Node Docker Official Image
  • Using Environment Variable With Angular
  • Docker Commands Beginners Should Know
  • How to Integrate a Distributed Database With Event Streaming

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

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

Let's be friends: