DEV Community

technonotes-hacker
technonotes-hacker

Posted on

Docker A to Z

docker ( double tab )

Image description

Help command

docker volume help
docker image help
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

docker info

  • docker system information will be displayed.

Image description

Image description

  • Above highlighted option will be ENABLED when we use CLUSTER in docker.

docker system df

  • All images & containers will be displayed.

Image description

Docker real-time Events or logs

docker system events
Enter fullscreen mode Exit fullscreen mode

Image description

docker system prune

  • It deletes all image and container.
  • Its a risky command as it removes unused data & free size.

Image description

help or man

man docker system
or
docker system help

Enter fullscreen mode Exit fullscreen mode

docker stats

Image description

  • Usage details are shown here.

docker search busapp

  • this search command , will get all the application i.e busapp installed in public repository of docker.

Image description

Image description

Image description

Image description

docker images

  • List the images which are present in the system.

Image description

Pulling the image from HUB

  • why am I pulling the image ? To launch a container I need an image.
docker pull httpd
docker images
docker pull alpine
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description

Where these images stored ?

  • It will be occupying your disc.
  • Check it with df command.
docker system df
Enter fullscreen mode Exit fullscreen mode

Image description

How to run a IMAGE ?

  • There are two things , one is create & run
  • CREATE --> Create the container but not in running state.
  • RUN --> Create the container & run the container too.
docker run --name testing_web httpd
docker ps

--name --> Name for the container 
httpd --> name of the image

Enter fullscreen mode Exit fullscreen mode

Image description

Image description

  • But the above one is running in foreground , so you can't perform anything in that window . But the container will come up.

Image description

Image description

  • CONTROL + C ( now the container will not be available )

Image description

RUN the container in back-ground

docker run -d --name testing_web httpd
docker ps -a ( shows all the container running & stopped )
d --> for demonize which runs in back-ground 

Enter fullscreen mode Exit fullscreen mode
  • Running the same command will end up in error because as we are using the same container name . Even though we stopped but the container is still there. IN other words " Its stopped but still the container is available in that name.

Image description

  • Provide a NEW NAME to the container.
docker run -d --name testing_web_new httpd
docker ps
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description

Lets login to the CONTAINER

docker exec -it testing_web /bin/sh
docker exec -it testing_web /bin/bash

testing_web  --> container name
/bin/sh --> shell type , we ca use bash also.
it --> Interactive terminal 

Enter fullscreen mode Exit fullscreen mode

Here the trick is that , NOT all commands we can run inside this container . Check it. Also we are not aware what OS they used to build the image.

Image description

Image description

  • It will only files which are related to httpd only.
  • only these commands can be used inside the container.

Image description

Without logging in Can we execute COMMANDS ?

  • YES
  • Remove the 'it' from the command.
docker exec testing_web_new uname -a
docker exec testing_web_new hostname
docker exec testing_web_new mkdir /tmp/testing_dir
Enter fullscreen mode Exit fullscreen mode

Image description

Copy FILES from local to CONTAINER


docker cp <file_name_local> <container_id/conatiner_name>:<destination>
docker ps
docker cp local_file 6438c81d6841:/tmp
docker exec testing_web_new ls /tmp
docker cp local_file testing_web_new:/tmp
Enter fullscreen mode Exit fullscreen mode

Image description

Copy FILES from CONTAINER to Local

docker cp <file_name_local> <container_id/conatiner_name>:<destination>
touch local_to_container
docker ps
docker cp local_to_container 4b:/tmp
docker exec os_service_3 ls /tmp
rm local_to_container
docker cp 4b:/tmp/local_to_container .

Note : 4b --> Nothing but start of the container. You can give in this WAY.
Enter fullscreen mode Exit fullscreen mode

Image description

How to START & STOP the CONTAINER?

Image description

docker ps -a
docker stop testing_web_new
docker ps -a
docker start testing_web_new
docker start testing_web
Enter fullscreen mode Exit fullscreen mode

Image description

System related check for these containers

docker system df
docker stats
docker stats <container_name>
docker top <container_name>
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

How to remove the CONTAINER ?

  • Keep in Mind " You cant remove a RUNNING Container ". But we can with FORCE option.

Image description

Image description

  • Before remove , STOP the container. ( safest way )

Image description

docker ps
docker rm testing_web_new
docker rm -f testing_web_new
docker ps
docker stop testing_web
docker rm testing_web
docker ps
Enter fullscreen mode Exit fullscreen mode

docker logs

  • By giving the container Name , we can check the logs.
  • Start logs only visible.

Image description

  • LETS start the alpine and check the logs.

Image description

  • Above screen shows Alpine is started but its not running.
  • Alpine is just a OS , so we need to provide what type of bash is required.

Image description

docker run -d --name os_service_2 alpine /bin/sh --> NOT WORKING / ERROR
docker run -d --name os_service_1 alpine /bin/sh --> NOT WORKING / ERROR
docker run -d -it --name os_service_3 alpine /bin/sh
Enter fullscreen mode Exit fullscreen mode

Image description

System Prune

  • Clear the container.

Image description

Image description

docker system prune
Enter fullscreen mode Exit fullscreen mode

Image description

  • EXITED all got deleted.

Image description

Reference :

[ TO BE CONTINUED ]

Top comments (0)