Sunday, February 10, 2019

Docker Cheat Sheet

Docker Commands:

1.  Docker Version :
      docker -v

2.  List Container :
      docker ps -a

3.  List Image :
      docker image ls -a

4. Docker Pull:
    docker pull <image_name> 

5. To remove/delete Container
    docker rm -f  <container_id/name>

6. To delete an Image
     docker rmi <image_id/name>

7. To go inside container shell cli when running from an image
   docker run -it <Image_Name>


8. To go inside Container shell CLI when its already running:
     docker exec -t -i <Container_Name>  /bin/bash

9. To commit changes into a docker container & creating a new image out of it:
    docker commit <container_id>  <New Image Name>:<Tag>
   Example: docker commit 12132dqe dhananjay/superset:version1
   sha256 hash indicates that docker commit command  was  successful.

10. To create container from an image
     docker create <Image_ID> 

11. How to remove Docker from Linux :

   a) to identify what installed package you have, run 
       dpkg -l | grep -i docker
  b) Most probably the above command will give either of the one:
       docker.io OR docker-ce  
  c)  Run below commands based on Docker installation, for example for  docker.io:
        sudo apt-get purge -y docker.io OR sudo apt-get purge docker-ce
        sudo apt-get autoremove -y --purge docker.io
        sudo apt-get autoclean
        sudo rm -rf /var/lib/docker 
        sudo rm /etc/apparmor.d/docker
        sudo groupdel docker 
          
    
12. To exit from the container without stopping the container, enter  "Ctrl+P+Q" 

13. Docker Push:
        docker login
        docker tag <Image ID> <Dockerhub_username>/<Image ID>
        docker push  <>Dockerhub_username>/<Image ID> 


14. To restart existing container:
        docker container restart <Container_Name>
 
             




https://github.com/wsargent/docker-cheat-sheet

No comments:

Post a Comment