Docker

Docker

Docker commands

 List containers dk container ls -a
dk ps -a
 Start container with port forwarding     dk run --name dvtools -ti -d -p 8080:80 <imge> --name dvtools
  
  
 Tag an image     dk image tag <imgid> dvtools:latest dvtools:v2
 Tag image for Repo     dk image <img> dennysv/dvtools:latest

Quick commands for Images


         alias     alias dk='docker'    
Remove all images  dk image prune -a    
 Build Image  and tag dk build . -t dvtools:v1
 Check an image layers dk inspect <image ID>
 History of image creation dk image history <image>
 List Docker images     dk image ls
 Delete image dk image rm <contaier>
rmi
 Ignore files during build .dockerignore    
 Search official image     dk search --filter "is-official=true" ubuntu

DockerFile Quick reference

 COPY     Copy files in to the image
 Volume     Creates a Mountpoint as defined
 ENTRYPOINT   The executable that runs when container is run. It accepts input parameters, or takes from CMD
 EXPOSE Defines ports to be published.
 CMD Command to execute at start, will ignore input parameters. If ENTRYPOINT is defined CMD arguments are passed as arguments. Only 1 command allowed,  only last one will take effect.
 ENV Variables to be defined in the container.
 RUN     A command to be run in a new layer of Image being build
 FROM Define base image from which image is built. This is first instruction.
 WORKDIR         Working Directory of container

Difference between CMD and ENTRYPOINT

Both Entry point and CMD execute instructions at start of container, however behaviour differ. 
CMD : When only CMD is specified, it executes command and will ignore any parameters passed. 
ENTRYPOINT: Defines command to execute at start, then inputs are passed as arguments. If CMD also specified,  ENTRYPOINT will treat CMD as arguments than commands.

Use of CMD is preferred unless there is requirement to accept arguments for container run.