How I learned Docker in just 24 minutes
The Best Resources and tutorial are here.
After i had a conversation with my senior developer , I was forced myself to learn Docker, Because as a backend developer in startup need to focus on the some non-programming things also and that lead’s me to learn Docker.
I searched in a lot places but that didn’t gave me the good resources except these 3 resources => 2 videos and 1 blog.Links will be in the end of this blog.
What is Docker (in 2 lines):
Docker is a machine that runs inside your machine , it have OS(linux) that runs on all OS , and it have a less amount of Memory.
Let’s Start
Here i’ll tell how easy to use docker.We’re going to create two files.
First File
1.Create File
Dockerfile
(no extension)
touch Dockerfile
#Create file command in line
2 . Open Dockerfile:
nano Dockerfile
#I’m going to use nano text editor , you can use your favorite text editor.
3.Dockering Python — Flask APP
FROM python:3-onbuild
#image our Docker going to use , we’re using Python3
COPY . /usr/src/app
#coping our current folder to /usr/src/app
which is in Docker
RUN pip3 install -r requirements.txt
#install the libraries to run our flask app.
CMD ["python3","app.py","-h","0.0.0.0:5000"]
#the command that run our flask app in host 5000
Dockerfile
FROM python:3-onbuild
COPY . /usr/src/app
RUN pip3 install -r requirements.txt
CMD ["python3","app.py","-h","0.0.0.0:5000"]
# this command executes inside the docker os
4.Building image.
Run this command on your terminal
$ docker build -t Sharely:beta .echo "building our docker with the name of Sharely and it's a beta version"
Second File
docker-compose.yml
#To run multiple micro service
touch docker-compose.yml
#creating file
nano docker-compose.yml
#opening the file
Let’s compose:
docker-compose.yml
version 3.3 #Docker version(Some standards to follow )services: #services we have to run
Sharely: # the app we have just created
build: . # building the current folder Dockerfile
ports: # the port that it want to access from Internet
- 2000:5000 #Outer world : flask running server Host
what is 2000:5000
is right ?
5000
is the our flask app running but which is inside our Docker it’s on different OS now. so we need to map it the 2000
is the port that can access anywhere from the internet. You can keep anything not 2000:5000
I always use 5000:5000
Running the Docker:
docker compose up
#that’s all
docker ps
# to get all the running machine of docker.
Some useful resources for learning Docker:-
Understand what docker is:
This video explains why we need docker compose
Simple tutorial on how to use docker.