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.
- 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
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
-
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
-
To run the container interactively, you can do the below shit in the interactive mode so that you can run comamnds inside the container
now when we runsudo docker ps
we get a running contianer -
Yaha pe echo " .." is basically the command that is run inside the busybox contianer
-
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 giveCONTAINR_ID_1 CONTIANER_ID_2 ..
-
you can stop a runnig contianer by :
sudo docker stop CONTAINER_ID
To run the docker container and remove the alrady running one :
sudo docker run --rm -it cpp_test_tejal:1
Create a new image by committing the changes : sudo docker commit [CONTAINER_ID] [new_image_name]
- when i pull an img where is it stored?