Skip to content

Latest commit

 

History

History
219 lines (149 loc) · 4.53 KB

File metadata and controls

219 lines (149 loc) · 4.53 KB

Docker Instructions

Installation on Mac

To Install Docker on Mac, follow the instructions at below link.

https://docs.docker.com/docker-for-mac/install/

Installation on Windows

To install Docker on Windows, follow the intructions at below link.

https://docs.docker.com/docker-for-windows/install/

Installation on Linux Distribution

To install Docker on Linux, follow the instructions at below link.

Centos : https://docs.docker.com/engine/install/centos/

Ubantu : https://docs.docker.com/engine/install/ubuntu/

Debian : https://docs.docker.com/engine/install/debian/

Fedora : https://docs.docker.com/engine/install/fedora/

Docker Hub

To access Docker Hub, Please visit below url

https://hub.docker.com/

Docker Commands

  1. To check Docker Version :
 docker --version
 
  1. To Start the Docker on Linux :
  docker service docker start
  
  1. To Stop the Docker on Linux :
  docker service docker stop
  
  1. To check the running containers :
  docker ps
  
  1. To check all the containers (running and terminated) :
  docker ps -a
  
  1. To check docker images :
  docker image
  
  1. To remove an docker image :
  docker rmi $image_id
  
  1. To build a docker image from Dockerfile :
  docker build 
  docker build -t $imageName:tagName
  docker build -t my-test-app:1.0.0
  
  1. To Login to Docker Hub Repository :
 docker login
 
  1. To Push an image to DockerHub Repository :
 docker push $dockerHubId/$imageId:$tagName
 docker push shubhamkushwah123/my-test-app:1.0.0
 
  1. To Pull an image from DockerHub Repository :
 docker pull $dockerHubId/$imageId:$tagName
 docker pull shubhamkushwah123/my-test-app:1.0.0
 
  1. To Run an Docker image :
 docker run -p $entryPort:$PortToBeMapped -d $dockerId/$imageId:$tagName
 docker run -p 8888:8080 -d shubhamkushwah123/my-test-app:1.0.0
 

Dockerfile Keywords

  1. FROM : It tells docker from which base image, you want to create your image from. Usage :
FROM <image>
FROM <image>:<tag>
  1. RUN : This command is used to run the instructions against the image. Usage :
RUN <command>
  1. CMD : CMD is used to provide default arguments for the ENTRYPOINT instruction, both the CMD and ENTRYPOINT instructions should be specified with the JSON array format. Note : Please note that there can only be one CMD in a Dockerfile. Usage :
CMD <command> <param1> <param2> (shell form)
  1. MAINTAINER : It is used to specify the maintainer of the Dockerfile. In our case, we just specify the email id. Usage :
MAINTAINER <name>
  1. ADD : Adds new files, directories, or remote file URLs from and adds them to the filesystem of the image at the path . Usage :
ADD <src>  <dest>
  1. ENTRYPOINT : Allows you to configure a container that will run as an executable. Usage :
ENTRYPOINT <command> <param1> <param2> (shell form)
  1. ENV : The ENV instruction sets the environment variable to the value . Usage :
ENV <key> <value>
  1. EXPOSE : It Informs Docker that the container listens on the specified network port(s) at runtime. Usage :
EXPOSE <port> [<port> ...]
  1. USER : The USER instruction sets the user name or UID to use when running the image and for any RUN, CMD and ENTRYPOINT instructions that follow it in the Dockerfile. Usage :
USER <username | UID>
  1. VOL : Creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers. Usage :
VOLUME <path>
  1. COPY : Copies new files or directories from and adds them to the filesystem of the image at the path . Usage :
COPY <src> [<src> ...] <dest>
  1. WORKDIR : Sets the working directory for any RUN, CMD, ENTRYPOINT, COPY, and ADD instructions that follow it. Usage :
WORKDIR </path/to/workdir>
  1. ARG : Defines a variable that users can pass at build-time to the builder with the docker build command. Usage :
ARG <name>[=<default value>]

Dockerfile Example

FROM openjdk:8-jdk-alpine

VOLUME /tmp

EXPOSE 8888

ARG JAR_FILE=/target/*.jar

COPY ${JAR_FILE} app.jar

RUN echo "Creation of your docker image is in progress, please hold on for a moment"

ENTRYPOINT ["java", "-jar", "app.jar"]

MAINTAINER "shubhamkushwah123@gmail.com"