Docker Basic Commands


1) Run

docker run nginx

It will try to find the image locally, if not found it will fetch from docker hub.



2) ps

docker ps

list all running containers

docker ps -a

all container, even they are stopped

3) stop

Stop running container

Container id

docker stop <name>

4) rm

remove permanently docker container which is not in use/stopped 


docker rm <name>

5) images

List images present on host

docker images


6) rmi

Remove images from host

docker rmi  nginx

make sure no container is running from that image. Delete all dependent containers to remove image.

7)  pull

Download an image without running and stores it.


docker pull nginx

8) sleep

docker run ubuntu sleep 5

it wait for 5 sec before container stops


9) exec


execute a command
 
docker exec flamboyant_mcclintock cat /etc/hosts


10) Attach/Detach


when running an image it will run  web app in attached mode on foreground


docker run ngnix


in background 

docker run -d ngnix

docker attach number (back to fore ground)





If you like please follow and comment