Useful Docker Commands for Beginners

Joseph Khan
Frontend Weekly
Published in
3 min readApr 22, 2020
Useful Docker Commands for Beginners

Docker is a container technology that helps you to deploy applications. It can be any application — a Node server application, a Database, a PHP application, a Java API server, etc. This article covers some very useful Docker Commands for Beginners.

A Docker container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.

Imagine, we have to deploy a Node Express server application onto different environments. For example, I develop my express server on my local computer using Node 10. So I test everything and it works fine. Now, I need to deploy it on a QA box which is running Node 9. After that, I need to deploy my application on a staging server which runs Node 11. And then I go to production. All the way, I see that there are differences in the Node versions being used by different environments. This can be a big problem, isn’t it? While the application works on my computer, it can break when deployed onto another box.

Very Useful Docker Commands for Beginners

This is where Docker comes in. If I bootstrap my Node Express server inside a Docker container running Node 10, then I can deploy the Docker container on all the environments and launch my Node express server. I need not worry about the system and version differences. Docker container creates an isolated environment for my application to run.

Docker Commands for Beginners

Docker is easy to install and set up. Go ahead and try it. Here is a very detailed step by step guide on Developing a Node server and running it using Docker.

Alright, now here are a few useful Docker commands for beginners.

Useful Docker Commands for Beginners

1. Log in to Docker CLI (so that you can push & pull images)

docker login

2. Logout

docker logout

3. List all Docker images in your computer

docker images -a

4. Build a Docker image. This will create the latest version of the image

docker build -t your_docker_username/aws-react-app .

5. Build a Docker image with a version/tag. This will create v1.0.0 of the image

docker build -t your_docker_username/aws-react-app:v1.0.0 .

6. Run a Docker image. Either on your local computer or remotely inside an AWS EC2 instance.

docker run -p 80:5000 your_docker_username/aws-react-app:v1.0.0

7. Run the Docker image in detached/background mode

docker run -p 80:5000 -d your_docker_username/aws-react-app

8. Delete a Docker image. (use -force if you get any error)

docker image rm your_docker_username/aws-react-app:v2.1.0

9. Delete All Docker images

docker rmi $(docker images -a -q) --force

10. Get running Docker image container ID.

docker ps

11. Stop the running Docker process/image

docker stop Container_ID

12. Push Docker image to Docker hub

docker push your_docker_username/aws-react-app:v1.0.0

13. Pull Docker image from Docker hub

docker pull your_docker_username/aws-react-app:v1.0.0

** Replace your_docker_username with your username.

Once again here is a very detailed guide on Getting Started with Docker. Happy Dockering. Cheers!

Further Reference: Docker official site.

Cheers! And yes, do share your thoughts by saying a Hi on my Twitter handle.

If you enjoyed this post and want similar articles to be delivered to your inbox directly, you can subscribe to my newsletters.

Originally published at https://josephkhan.me on April 22, 2020.

--

--

Joseph Khan
Frontend Weekly

Engineering Manager | Author & Speaker. I work with one of the largest OTA (Online Travel Agencies) in the Middle East https://josephkhan.me/