Subscribe to get my new tutorials in your inbox.

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.

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 Important Docker commands for beginners.

Useful Docker commands for Beginners

1. Login 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

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 Docker process/image

docker stop Container_ID

12, Check logs from inside Docker daemon

docker logs Container_ID

13. Push Docker image to Docker hub

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

14. Pull 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.


If you enjoyed this post and want similar articles to be delivered to your inbox directly, you can subscribe to my newsletters. I send out an email every two weeks with new articles, tips & tricks, news, free materials. No spamming, of course.

Write a Comment

Your email address will not be published. Required fields are marked *