8 Basic Docker Commands || Docker Tutorial 4

TechWorld with Nana · Beginner ·☁️ DevOps & Cloud ·6y ago

Key Takeaways

Covers basic Docker commands and Docker port mapping

Full Transcript

[Music] so in this video I'm gonna show you some basic doc recommends at the beginning I'm gonna explain what the difference between container and image is because that's something a lot of people confuse then very quickly go through version intake and then show you a demo of how to use the basic docker comments commands that will be enough to pull an image locally to start a container to configure a container and even debug the container so with that said let's get started so what is the difference between container and image mostly people use those terms interchangeably but actually there is a fine difference between the two to see theoretically image is just the part of the container runtime so container is the running environment for an image so as you see in this graphic the application image that runs the application could be Postgres Reddy's some other application needs let's say a file system where it can save the log files or where it can store some configuration files it also needs some environmental configuration like environmental variables and so on so all this environmental stuff are provided by container and container also has a port that is binded to it which makes it possible to talk to the application which is running inside of a container and of course it should be noted here that the file system is virtual in the constant container so the container has its own abstraction of an operating system including the file system and the environment which is of course different from the file system and environment of the host machine so in order to see the difference between container and image in action let's head over to the talker hub and find example a Redis image another thing is that docker hub all the artifacts that are in the docker hub are images so we're not talking about containers here all of these things are images talker official image so we're gonna go ahead and pull a Redis image out of the docker hub to my laptop so you see the different layers of the image are downloaded and this will take a couple of minutes so once the download is complete I can check all the existing images on my laptop using docker images command so I see I have two images readies and Postgres with text image IDs and so on another important aspect of images is that they have texts or versions so for example if we go back to the dock hub each one each image that you look up in the docker hub will have many different versions the latest is always the one that you get when you don't specify the version of course but if you have a dependency on a specific version you can actually choose the version you want and specified you can select one from here so this is what you see here the tag is basically the version of the image so I just downloaded the latest and I can also see the size of the image so now to this point we have only worked with images there is no container involved and there's no Redis running so now let's say I need readies running so that my application can connect to it I'll have to create a container of the Redis image that will make it possible to connect to the Redis application and I can do it by running the Redis image so if I say docker run Redis this will actually start the image in a container so as I said before container is a running environment of an image so now if I open a new tab and do docker PS I will get stairs of all the running docker containers so I can see the container radius is running with a container ID based on the image of Redis and some other information about it for example the port that it's running on and so on so as you see here the docker run readies command will start the race container in the terminal in an attached mode so for example if I were to terminate this with a control C you see that Redis application stops and the container will be stopped as well so if I do docker PS again I see that no container is running so there is an option for docker run command that makes it able makes it possible to run the container in a detached mode and that is minus D so if I do docker run - t Redis I will just get the ID of the container as an output and the container will stop running so if we check again docker PS I see the container with the ID starting with 8 3 8 which is the same thing here is running so this is how you can start it in a detached mode now for example if you would want to restart a container because I don't know some the application crashed inside or some error happens so you want to restart it you would need the container ID so just the first part of it not the whole string and you can simply say doctor stop idea of the container and that will stop the docker container I think running if you want to start it again you can use the same ID to start the game so let's say you stopped docker container at the end of the day you go home you come back the next day open your laptop and you want to restart the stop container right so if you do dr. PS there is the output it's empty you don't see any containers so what you can do alternative to just looking up your history command-line history is you can do docker PS - a which will show you all the containers which are running or not running so here you see the container ID again and you can restart it okay so let's try another thing let's say you have two parallel applications that both use Redis but in different versions so you would need to read ease containers with different image versions running on your laptop right at different times maybe or at the same time so so here we have the latest one which is ready 5:06 and let's head over to the docker hub in select version let's say you need version 4.0 so remember the first time that we downloaded the Redis image we did dr. pol Redis however if you run docker if you use docker run with Redis image and the tech which was 4.0 it will pull the image and start the container right away after it so it does two commands basically in one so it's dr. pol that doctor start in one comment so if I do this it says it can find the image locally so it goes and pulls the image from the repository to my laptop and again we see some layers are downloaded and the container is started right away and now if I do dr. PS you see that I have two radiuses running so this is where it gets interesting now how do you actually use the any container that you just started so in this output we you also see the ports section which specifies on which port the container is listening to the incoming requests so both containers open the same port which is what was specified in the image so in the logs of the container you can see the information running mode standalone port six three seven nine so how does that actually work and how do we not have conflicts while both are running on the same port so to explain that let's head over to our slide and see how this works as you know container is just a virtual environment running on your host and you can have multiple containers running simultaneously on your host which is your laptop PC whatever you working on and your laptop has certain poe ports available then you can open for certain applications so how it works is that you need to create a so-called binding between a port that your laptop your host machine has and the container so for example in the first container part here you see container is listening on port 5000 and you bind your laptop's port 5000 to that containers now you will have conflict if you open to 5,000 ports on your hosts because you will get a message the port is already bound or is already in use you can do that however you can have two containers as you see in the second and third containers are both listening on port 3000 which is absolutely okay as long as you bind them to two different ports from your host machine so once the port binding between the host and the container is already done you can actually connect to the running container using the port of the host so in this example you are I you would have some F local host and then the port of the host and the host then we'll know how to forward the request to the container using the port binding so if we head back here you see that containers have their ports and their report running on the same one however we have made any binding between my laptop's ports and the container port and because of that the container is basically unreachable by any application so I won't be able to use it so the way we actually do that is by specifying the binding of the ports during the run command so I'm gonna break this and check that there is just one container running no I'm gonna stop the other one as well so we can start them in you okay so we see both containers are here so now we want to start them using the binding between the host and the container ports but again we have to read is's so we need to bind them to two different ports on my laptop so the way to do it is you do docker run and you specify with - P the port of the host that's the first one so let's go with 6000 it doesn't really in this case and the second one is the port that you're binding this tube which is the container port so we know the container port will be six three seven nine and this is where we bind our so my laptop's port 6002 and if I do this here so you know if I do PS that's actually clean this here you see the binding here alright so your laptop's 6,000 port is bound to the containers six three seven nine so now let's do another thing and let's start it in a detached mode like this let's check again it's running again and now I want to start the second container that's clear this again so here you see it created a bunch of containers because when I specified different options with the port binding it actually created new containers that's why you see a couple of them over here so I'm gonna copy the image name with the tag for that o- p so for example if I were to do this now and I would try to run the other readies the second readies container with the same port on my laptop I would get an error saying port is already allocated so I can do six thousand one and run it again I'll run it in detached mode and if I go over here and say docker PS I see that i have two different Redis versions running both of them bound to different ports on my laptop and they the containers themselves listening to requests on the same port thanks for watching the video I hope it was helpful and if it was don't forget to like it this is a video series so I will create a new one every week so if you want to be notified whenever a new video comes out then subscribe to my channel if you have any questions if something wasn't clear in the video please post them in the comment section below and I will try to answer them so thank you and see you in the next video

Original Description

Learn the most important docker commands by example. As well as how Docker port mapping works. ► Subscribe to me on Youtube: https://bit.ly/2z5rvTV In this video I show you some basic docker commands. In the beginning I explain the difference between docker image and container and go through the topics of version and tag in an docker image. The main part is the demo, where I show you how to use these basic docker commands. T i m e s t a m p s 🐳 - 2:25 docker pull - 4:04 docker run - 4:40 docker ps - 5:06 docker run --options - 6:17 docker stop - 6:43 docker start - 10:08 - docker ports, docker port mapping - docker logs (in part 2) - docker exec -it (in part 2) #docker #techworldwithnana #devops #dockertutorials 👉🏼 Part 2 - basic commands, which are useful for troubleshooting: https://www.youtube.com/watch?v=tLK9nNFHWH8 For any questions/issues/feedback, please leave me a comment and I will get back to you as soon as possible. ►► Full Docker and Kubernetes Tutorial Playlist: https://bit.ly/2YGeRp9 This video is the 4th of a complete series for beginners, where I explain the basic concepts and also show you demo's like deploying your containerized application. At the end of this tutorial you will fully understand Docker and Kubernetes. 💡 Only interested in Docker? ►► Complete Docker Tutorial Playlist: https://bit.ly/2ymJHbX #docker #whatisdocker #dockertutorials #devops #techworldwithnana ------------------------------------------------------------------------------------- The complete step-by-step guide to Docker and Kubernetes will include the following content: 🐳 D O C K E R - Container concept - Why docker? (image vs. traditional DevOps) - Install docker on different operating systems - 8 basic commands you need to know - Docker vs. Virtual Machine - Docker in Practice: Overview of whole development process with Docker (development, continuous delivery, deployment) - Develop an application with Docker - Docker Compo
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from TechWorld with Nana · TechWorld with Nana · 4 of 60

1 What is Docker? Docker container concept explained || Docker Tutorial 1
What is Docker? Docker container concept explained || Docker Tutorial 1
TechWorld with Nana
2 What is a Docker Container? Docker Demo || Docker Tutorial 2
What is a Docker Container? Docker Demo || Docker Tutorial 2
TechWorld with Nana
3 How to install docker? Step by Step || Docker Tutorial 3
How to install docker? Step by Step || Docker Tutorial 3
TechWorld with Nana
8 Basic Docker Commands || Docker Tutorial 4
8 Basic Docker Commands || Docker Tutorial 4
TechWorld with Nana
5 Debugging Docker Containers with docker exec and docker logs || Docker Tutorial 5
Debugging Docker Containers with docker exec and docker logs || Docker Tutorial 5
TechWorld with Nana
6 Docker vs Virtual Machine | simply explained || Docker Tutorial 6
Docker vs Virtual Machine | simply explained || Docker Tutorial 6
TechWorld with Nana
7 Overview of Workflow with Docker - Docker in Practice || Docker Tutorial 7
Overview of Workflow with Docker - Docker in Practice || Docker Tutorial 7
TechWorld with Nana
8 Developing with Docker - Docker in Practice || Docker Tutorial 8
Developing with Docker - Docker in Practice || Docker Tutorial 8
TechWorld with Nana
9 Docker Compose Tutorial - Docker in Practice || Docker Tutorial 9
Docker Compose Tutorial - Docker in Practice || Docker Tutorial 9
TechWorld with Nana
10 Dockerfile Tutorial - Docker in Practice || Docker Tutorial 10
Dockerfile Tutorial - Docker in Practice || Docker Tutorial 10
TechWorld with Nana
11 Private Repository explained | Registry on AWS - Docker in Practice || Docker Tutorial 11
Private Repository explained | Registry on AWS - Docker in Practice || Docker Tutorial 11
TechWorld with Nana
12 Docker Volumes explained in 6 minutes
Docker Volumes explained in 6 minutes
TechWorld with Nana
13 Deploying the containerized application with Docker Compose || Docker Tutorial 12
Deploying the containerized application with Docker Compose || Docker Tutorial 12
TechWorld with Nana
14 Docker Volumes Demo || Docker Tutorial 13
Docker Volumes Demo || Docker Tutorial 13
TechWorld with Nana
15 Docker vs Kubernetes vs Docker Swarm | Comparison in 5 mins
Docker vs Kubernetes vs Docker Swarm | Comparison in 5 mins
TechWorld with Nana
16 What is Kubernetes | Kubernetes explained in 15 mins
What is Kubernetes | Kubernetes explained in 15 mins
TechWorld with Nana
17 Kubernetes Components explained! Pods, Services, Secrets, ConfigMap | Kubernetes Tutorial 14
Kubernetes Components explained! Pods, Services, Secrets, ConfigMap | Kubernetes Tutorial 14
TechWorld with Nana
18 Kubernetes Architecture explained | Kubernetes Tutorial 15
Kubernetes Architecture explained | Kubernetes Tutorial 15
TechWorld with Nana
19 Benefits of Kubernetes | Scalability, High Availability, Disaster Recovery | Kubernetes Tutorial 16
Benefits of Kubernetes | Scalability, High Availability, Disaster Recovery | Kubernetes Tutorial 16
TechWorld with Nana
20 Minikube and Kubectl explained | Setup for Beginners | Kubernetes Tutorial 17
Minikube and Kubectl explained | Setup for Beginners | Kubernetes Tutorial 17
TechWorld with Nana
21 Top 3 programming languages to learn in 2020 | meta analysis
Top 3 programming languages to learn in 2020 | meta analysis
TechWorld with Nana
22 Kubectl Basic Commands - Create and Debug Pod in a Minikube cluster | Kubernetes Tutorial 18
Kubectl Basic Commands - Create and Debug Pod in a Minikube cluster | Kubernetes Tutorial 18
TechWorld with Nana
23 Kubernetes YAML File Explained - Deployment and Service | Kubernetes Tutorial 19
Kubernetes YAML File Explained - Deployment and Service | Kubernetes Tutorial 19
TechWorld with Nana
24 Run Jenkins in Docker Container - Jenkins Pipeline Tutorial for Beginners 1/4
Run Jenkins in Docker Container - Jenkins Pipeline Tutorial for Beginners 1/4
TechWorld with Nana
25 Create Multibranch Pipeline with Git - Jenkins Pipeline Tutorial for Beginners 2/4
Create Multibranch Pipeline with Git - Jenkins Pipeline Tutorial for Beginners 2/4
TechWorld with Nana
26 Jenkinsfile - Jenkins Pipeline Tutorial for Beginners 3/4
Jenkinsfile - Jenkins Pipeline Tutorial for Beginners 3/4
TechWorld with Nana
27 Trigger Jenkins Build automatically - Jenkins Pipeline Tutorial for Beginners 4/4
Trigger Jenkins Build automatically - Jenkins Pipeline Tutorial for Beginners 4/4
TechWorld with Nana
28 Complete Application Deployment using Kubernetes Components | Kubernetes Tutorial 20
Complete Application Deployment using Kubernetes Components | Kubernetes Tutorial 20
TechWorld with Nana
29 Kubernetes Namespaces Explained in 15 mins | Kubernetes Tutorial 21
Kubernetes Namespaces Explained in 15 mins | Kubernetes Tutorial 21
TechWorld with Nana
30 Configure Build Tools in Jenkins and Jenkinsfile | Jenkins Tutorial
Configure Build Tools in Jenkins and Jenkinsfile | Jenkins Tutorial
TechWorld with Nana
31 Complete Jenkins Pipeline Tutorial | Jenkinsfile explained
Complete Jenkins Pipeline Tutorial | Jenkinsfile explained
TechWorld with Nana
32 Kubernetes Ingress Tutorial for Beginners | simply explained  | Kubernetes Tutorial 22
Kubernetes Ingress Tutorial for Beginners | simply explained | Kubernetes Tutorial 22
TechWorld with Nana
33 What is Helm in Kubernetes? Helm and Helm Charts explained  | Kubernetes Tutorial 23
What is Helm in Kubernetes? Helm and Helm Charts explained | Kubernetes Tutorial 23
TechWorld with Nana
34 How Websites Work | simply explained with examples
How Websites Work | simply explained with examples
TechWorld with Nana
35 What is JavaScript? | JavaScript Tutorial #1
What is JavaScript? | JavaScript Tutorial #1
TechWorld with Nana
36 What is Ansible | Ansible Playbook explained | Ansible Tutorial for Beginners
What is Ansible | Ansible Playbook explained | Ansible Tutorial for Beginners
TechWorld with Nana
37 JavaScript Variables & JavaScript Data Types explained | JavaScript Tutorial #2
JavaScript Variables & JavaScript Data Types explained | JavaScript Tutorial #2
TechWorld with Nana
38 How Prometheus Monitoring works | Prometheus Architecture explained
How Prometheus Monitoring works | Prometheus Architecture explained
TechWorld with Nana
39 Where to write JavaScript | Where to execute JavaScript Code | JavaScript Tutorial #3
Where to write JavaScript | Where to execute JavaScript Code | JavaScript Tutorial #3
TechWorld with Nana
40 JavaScript Operators & JavaScript Conditionals | JavaScript Tutorial #4
JavaScript Operators & JavaScript Conditionals | JavaScript Tutorial #4
TechWorld with Nana
41 Pods and Containers - Kubernetes Networking | Container Communication inside the Pod
Pods and Containers - Kubernetes Networking | Container Communication inside the Pod
TechWorld with Nana
42 Kubernetes Volumes explained | Persistent Volume, Persistent Volume Claim & Storage Class
Kubernetes Volumes explained | Persistent Volume, Persistent Volume Claim & Storage Class
TechWorld with Nana
43 Kubernetes ConfigMap and Secret as Kubernetes Volumes | Demo
Kubernetes ConfigMap and Secret as Kubernetes Volumes | Demo
TechWorld with Nana
44 Pull Image from Private Docker Registry in Kubernetes cluster | Demo
Pull Image from Private Docker Registry in Kubernetes cluster | Demo
TechWorld with Nana
45 Kubernetes StatefulSet simply explained | Deployment vs StatefulSet
Kubernetes StatefulSet simply explained | Deployment vs StatefulSet
TechWorld with Nana
46 Yaml Tutorial | Learn YAML in 18 mins
Yaml Tutorial | Learn YAML in 18 mins
TechWorld with Nana
47 Terraform explained in 15 mins | Terraform Tutorial for Beginners
Terraform explained in 15 mins | Terraform Tutorial for Beginners
TechWorld with Nana
48 Setup Prometheus Monitoring on Kubernetes using Helm and Prometheus Operator | Part 1
Setup Prometheus Monitoring on Kubernetes using Helm and Prometheus Operator | Part 1
TechWorld with Nana
49 Managed Kubernetes Cluster explained | Kubernetes on Cloud (1/2)
Managed Kubernetes Cluster explained | Kubernetes on Cloud (1/2)
TechWorld with Nana
50 Step by Step Application Deployment on LKE using Helm | Kubernetes on Cloud (2/2)
Step by Step Application Deployment on LKE using Helm | Kubernetes on Cloud (2/2)
TechWorld with Nana
51 Kubernetes Operator simply explained in 10 mins
Kubernetes Operator simply explained in 10 mins
TechWorld with Nana
52 What is Infrastructure as Code? Difference of Infrastructure as Code Tools
What is Infrastructure as Code? Difference of Infrastructure as Code Tools
TechWorld with Nana
53 AWS EKS - Create Kubernetes cluster on Amazon EKS | the easy way
AWS EKS - Create Kubernetes cluster on Amazon EKS | the easy way
TechWorld with Nana
54 Prometheus Monitoring - Steps to monitor third-party apps using Prometheus Exporter | Part 2
Prometheus Monitoring - Steps to monitor third-party apps using Prometheus Exporter | Part 2
TechWorld with Nana
55 GitHub Actions Tutorial - Basic Concepts and CI/CD Pipeline with Docker
GitHub Actions Tutorial - Basic Concepts and CI/CD Pipeline with Docker
TechWorld with Nana
56 Docker Tutorial for Beginners [FULL COURSE in 3 Hours]
Docker Tutorial for Beginners [FULL COURSE in 3 Hours]
TechWorld with Nana
57 Kubernetes Services explained | ClusterIP vs NodePort vs LoadBalancer vs Headless Service
Kubernetes Services explained | ClusterIP vs NodePort vs LoadBalancer vs Headless Service
TechWorld with Nana
58 Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]
Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]
TechWorld with Nana
59 Containers on AWS Overview: ECS | EKS | Fargate | ECR
Containers on AWS Overview: ECS | EKS | Fargate | ECR
TechWorld with Nana
60 Kubernetes is dropping Docker support - What does it mean for YOU?
Kubernetes is dropping Docker support - What does it mean for YOU?
TechWorld with Nana

Related AI Lessons

`wrangler dev --remote` silently writes to your production KV namespace — here's the fix
Learn how to safely use wrangler dev --remote with live KV namespaces without overwriting production data
Dev.to · 강해수
Qwen 3.6 27B Is the Local Dev Sweet Spot — Here's Why
Discover why Qwen 3.6 27B is the ideal choice for local development, and how it can boost your productivity
Dev.to · Carter May
Deploying Spring Petclinic Microservices with Docker Compose: An End-to-End DevOps Deployment Experience
Learn to deploy Spring Petclinic microservices with Docker Compose for a seamless DevOps experience
Dev.to · Nice Nwogu
Qwen 3.6 27B Is the Local Dev Sweet Spot — Here's Why
Discover why Qwen 3.6 27B is the ideal choice for local development, offering a sweet spot for efficiency and performance
Dev.to · Carter May
Up next
Containers on Amazon ECS with Mama J
AWS Developers
Watch →