gaurav0401 / docker-guide

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docker Guide


Docker is an open platform which packages application and its dependencies in a form of container.It used to developing , shipping and running an application.

Docker Terminology

  • Docker File: It is a text document which contains all those commands that will be used to assemble an docker image
  • Docker Image:It is a template for creating a docker container.
  • Docker Container:It is the running instance of docker image.It holds entire package to run application.
  •                  build                        run
     Docker File -------------> Docker Image --------------> Docker Container 
    


Installing Docker

  • Install linux distro on your system using How to install wsl for windows 11.
  • Now , go to the Docker Engine Install and download docker according of your operating system.
  • Install downloaded file of docker and restart you system. Then sign-up on docker.
  • Now go to the cmd and type 'docker -v' to check the version of the installed docker.
  • Now run a given command to to run first docker image 'docker run hello-world' , if the command get executed successfully it means docker has been successfully installed on your system.

Useful docker commands

  • code .:used to open folder in a vs code
  • docker -v:used to check docker version.
  • docker pull 'image name':used to pull image from a repository.
  • docker pull 'image name:tag name':used to pull image of specific version.
  • docker images: It lists all the available images in our docker.
  • docker search 'term':used to search images related to particular name/term .
  • docker run 'image name':used to start container.
  • docker ps:It is used to shows the running containers.
  • docker ps -a/--all:It is used to show all containers.
  • docker ps -n/-last:It shows last created containers including all states.
  • docker ps -f "status=running/exited":It is used to show the filtered containers list based on thier status.
  • docker run --name 'give name' -d 'image name /id':It is used to provide a name to container before running that container
  • docker run --name 'give name' -it -d 'image name':Used to run image with interaction mode.
  • docker exec -it 'container id' 'command':It is used to run a new command for a running container.
  • docker inspect 'container id':used to inspect container.
  • docker stop 'container name':It is used to stop running container.
  • docker stop 'container ids...':used to stop multiple containers at once.
  • docker rm 'container ids/name....':used to remove containers.
  • docker image rm 'image name':Used to remove images.
  • docker restart 'container name/id':used to restart container again.
  • docker login:used to login into docker hub to our push images there
  • docker commit:It is used to save a state of existing container as a new image.
  • docker push :used to push / upload docker images to docker hub.
  • docker copy:used to copy local files into docker image.
  • docker logs:used to retrieves logs of container at the time of execution.
  • docker volume: It is a independent file system of docker which is used to create volumes to store container's data.
  • docker log out:used to log out from docker hub.
  • WORKDIR: used to set current working directory for instructions in dockerfile.
  • COPY: used to copy files from source to destination directory.
  • docker rm -f 'container ids....' used to remove all containers forcefully.
  • docker build -t 'image name' 'path(where docker file is located)':used to create new image.
  • docker run -p using port : allocated port (8001:8000) 'image name':used to run container on a specific port number.

Building an image in docker

  • Create dockerfile in the separate folder with name 'Dockerfile' (Note:Dockerfile is no extension).
  • Now write commands in docker files .
  • Now go to terminal and write build command for creating an image from dockerfile which is mentioned above.
  • It will takes sometime to create image. Once completed you can check your image using 'docker images' command.
  • Now you can use that image to create containers.

About