Installing Docker on Linux
-
Script Based Approach:
- Execute the following commands on your linux instance
curl -fsSL https://get.docker.com -o get-docker.sh sh get-docker.sh
- Add user to docker group
-
Instruction Based Approach: Refer Here
Dockerfile Instructions
- EXPOSE:
- This instruction informs Docker that the application listens on the specific network ports at runtime.
- Two Protocols can be specified TCP and UDP. TCP is default
- Syntax:
EXPOSE <port> [<port/protocol>]
- Example
FROM openjdk:8 RUN wget https://referenceappkhaja.s3-us-west-2.amazonaws.com/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar EXPOSE 8080 ENTRYPOINT ["java"] CMD ["-jar", "spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar"]
- Execute the following commands
docker image build -t spc:0.1 . docker container run -P -d spc:0.1 docker container ls
- LABEL:
- This instructio adds metadata to an image
- Syntax
LABEL <key>=<value> <key>=<value>
- Example
FROM openjdk:8 LABEL author="khaja" LABEL version="0.2" LABEL project="QT" RUN wget https://referenceappkhaja.s3-us-west-2.amazonaws.com/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar EXPOSE 8080 ENTRYPOINT ["java"] CMD ["-jar", "spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar"]
- ADD and COPY:
- Both ADD and COPY instructions are used to copy the files into docker image.
- ADD instruction supports copying files from url and local machines
- COPY instructuon supports only copying files from local machines
- Syntax:
ADD <src> <dest> COPY <src> <dest>
- Example ADD with URL:
FROM openjdk:8 LABEL author="khaja" LABEL version="0.3" LABEL project="QT" ADD https://referenceappkhaja.s3-us-west-2.amazonaws.com/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar /spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar EXPOSE 8080 ENTRYPOINT ["java"] CMD ["-jar", "/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar"]
- Example Add/Copy with local path
FROM openjdk:8 LABEL author="khaja" LABEL version="0.4" LABEL project="QT" COPY spring-petclinic.jar /spring-petclinic.jar EXPOSE 8080 ENTRYPOINT ["java"] CMD ["-jar", "/spring-petclinic.jar"]