Skip to content

Latest commit

 

History

History
93 lines (66 loc) · 4.63 KB

basics.md

File metadata and controls

93 lines (66 loc) · 4.63 KB

Docker Tutorial

Reference Link Follwed


Docker search, docker images, docker pull

How does Docker work?

  • You can build docker images that hold your applications
  • You can create Docker containers from those Docker images to run your applications
  • You can share those Docker images via Docker Hub or your own registry.

image

  • Search for a docker image : docker search ubuntu
  • Search with filters : docker search --filter stars=3 ubuntu
  • If you want to provide multiple filters then do this : docker search --filter stars=100 --filter is-official=true ubuntu
  • If you want to see the description without any trucations do this :
    docker search -f stars=100 -f is-official=true --no-trunc ubuntu
  • List all the images that you have on host : docker images
  • Pull an img from dockerhub : docker pull java
  • To check fo r particular type of img present on ur system : docker images java
  • You can also provide tag while you provide name : docker images java:latest

Dokcer commads rquire root prieges. for more info - https://docs.docker.com/engine/install/linux-postinstall/

Note : you can also use sudo instead of going into root


Fundamentals of DockerFile

Dokcerfile - docker can build imgs automatically by reading the instructions given in the docker file its a text file in which terminal based commands are written When you build a dockerfile you get a docker image, when you run an image you get a contianer.

you name a dockerfile as Dockerfile and it is without an extension

  • To build a dockerfile : sudo docker build .

The current working directory is called the build context and the dockerfile is assumed to be present in thos directory
Everytime you change smthing in the dockerfile and build it, a new img is created

if you want to build the docker file from other directory , you simply provide the path woith -f
sudo docker build -f /home/tejal/docker/D1/Dockerfile .

  • To provide name the repo and tag : sudo docker build -t my_app:1 .
    where my_app represents the repo name and 1 represnts the tag

Docker Contianer Basics

  • To get the list of all the running contianer : sudo docker ps

  • To get the list of all the contianer that you have on your system use -a
    sudo docker ps -a

  • To run a contianer : sudo docker run options image_name commands args
    sudo docker run IMAGE_ID

  • To name the contianer so here --name is a flag : sudo docker run --name my_ubuntu_contianer 54f852336194
    when you run docker contianer it could run in atttched mode/ detached mode (in the background)

  • If you want to run in detached mode then : sudo docker run --name my_ubuntu_contianer_1 -d 54f852336194

  • The bada sa ID defines the contianer ID of the container
    you can us the short container ID that you se wile you list down the container list or you can this bada sa contianer id to work with the containers to delete it or do smthing shit
    image

  • To run the container interactively, you can do the below shit in the interactive mode so that you can run comamnds inside the container
    image
    now when we run sudo docker ps we get a running contianer

  • Yaha pe echo " .." is basically the command that is run inside the busybox contianer
    image

  • this runs the shell inside the contianer
    image

  • To remove a container just give the container ID of the contianer to be removed : sudo docker rm CONTAINDER_ID
    you can also rm multiple continers in 1 go just give CONTAINR_ID_1 CONTIANER_ID_2 ..

  • you can stop a runnig contianer by : sudo docker stop CONTAINER_ID


Build and run C++ applications in a docker container

To run the docker container and remove the alrady running one :
sudo docker run --rm -it cpp_test_tejal:1

Docker commit

Create a new image by committing the changes : sudo docker commit [CONTAINER_ID] [new_image_name]

Reference

Doubts

  • when i pull an img where is it stored?