Docker Commands for Beginners

Docker is similar to VMWare Workstation and Oracle VM VirtualBox. It enables host operating system (for example, Windows) to run guest operating system(s) on top of it.

Docker requires you to enable Hyper-V on Windows 10 Pro, while VirtualBox requires you to disable Hyper-V on Windows 10 Pro, so you cannot run both virtualization technology on the same OS.

Docker is widely preferred because of its efficiency in using computer resources.

  1. List all images
    docker images -a
  2. Remove an image
    docker rmi 
  3. List all containers
    docker ps -a
    docker container ls -a
  4. Pull an image
    docker pull :
    docker pull ubuntu:latest
  5. Run a container
    docker run -d -it --name  
    docker run -d -it --name myubuntu ubuntu
  6. Stop a container
    docker stop 
  7. Remove a container
    docker rm 
  8. Attach to a running container
    docker attach 
  9. Commit a container (save it as an image)
    docker commit  
  10. Execute command
    docker exec  
    docker exec myubuntu bash -c "ls -aF /home; cat /etc/passwd"
  11. Expose container ports to host
    docker run -it -d -p : 
    docker run -it -d -p 9100:9100 -p 9090:9090 --name mycentos centos

 

 

Leave a Reply