Docker in simple words

Docker in simple words

No alt text provided for this image

It is a opensource platform. It virtualize the O.S(that means apps can run independently on a single machine).

Just like Hypervisors uses single hardware to create multiple VM’s(Virtual Machines) that works independently. So does the Docker make use of single

Containers?are running instance of an image. These are very small software packages/apps with all the libraries and dependencies that can run on any machine on which the docker is installed.

Dockers eliminates the need of

  • Multiple VM’s by making use single kernel and sharing it with all the apps(Containers)
  • No need to deploy multi VM’s for running the apps in isolated environment.

Dockers uses Alpine Linux which is light weight as compared with full blown O.S.

Dockerfile

It is a file without any extensions and it is only understood by the Docker how to build the image.

For example:-

FROM python:3.9-sli

RUN mkdir /code

COPY . /code/

CMD python run.pym        

  • When?docker build .?executed in Docker CLI , Docker will search for Dockerfile and follow the instructions and will build an image.
  • After building an image we can see the images using command?docker images .
  • docker ps?command used to see the running containers.
  • To start container?docker run *image_name
  • Some useful?Docker Commands:
  • docker build . -t Django-dev

The above will execute the?Dockerfile?and whatever instructions given there it will create an image named “Django-dev” and will assign a terminal to it. Make sure your are right directory where the Dockerfile is located otherwise it give error.

  • docker run -it --rm Django-dev-> This will start the container.
  • docker image?-> To view all the Docker images
  • docker ps?-> To see all the docker running containers
  • docker ps -a?-> To see all docker running and stopped containers
  • docker rm *container_id?->This will?remove docker container?for e.g First you list docker container using?docker ps -a?and select the particular container id you want to delete?docker container rm cc3f2ff51cab cd20b396a061
  • docker stop *name?-> To?stop docker container. It is the necessary step before deleting the container because the container cannot be deleted unless it is stopped.
  • docker logs *container_id?-> To see the particular output of the container.

Docker Networking

When a container is created by default it is attached to a separate network and that will be not accessible to our machine. So to access the container into our local machine we need to bind the ports using the “-p”.

Default ports used by the most commonly used frameworks and databases:

  • Flask : 5000
  • MongoDB : 27017
  • Postgres : 543
  • Django : 8000

So we will bind it with our localhost port.

for e.g docker run -d --name mongo1 -p 27017:27017 mongo

要查看或添加评论,请登录

社区洞察

其他会员也浏览了