Dockerfile instructions (others)
-
ARG:
- is a variable that can be set during image build.
- Scope: This ARG value will be available till the image is built
- Refer Here
-
ENV:
- this will be environment variable available in RUN container
- These values can be set or changed while the container is created.
- Refer Here
-
ONBUILD
-
STOPSIGNAL
-
HEALTHCHECK
-
.dockerignore
CI/CD Pipeline with Docker containers
- Create a jenkins job
- Get the latest code from git
- Build the package using build tools like maven
- Using the package build create the docker image
- tag the docker image and send it to the registry
- pull the docker image from registry and deploy using k8s/swarm etc
Registry
- Collection of Docker Images
- DockerHub:
- Before uploading images (push) to docker hub, login into docker hub from command line
Sample Scenario: Push gameoflife to docker hub
- Clone the code
git clone https://github.com/wakaleo/game-of-life.git
- Build the code
mvn package
- Create a Docker file at the root folder of game-of-life
FROM tomcat:8
LABEL owner=none
EXPOSE 8080
ADD ./gameoflife-web/target/gameoflife.war /usr/local/tomcat/webapps/gameoflife.war
CMD ["catalina.sh", "run"]
- build the docker image
docker image build -t gol:1.0 .
- login to docker hub
docker log
username: shaikkhajaibrahim
password
- Now to push docker image to docker hub pattern is <username>/<imagename>:<tag>
docker image tag gol:1.0 shaikkhajaibrahim/gol:1.0
docker push shaikkhajaibrahim/gol:1.0
multistage builds
-
Multistage can be used to build applications and create docker images.
-
Lets build the application game of life using maven and create a docker image from the single docker file
FROM maven:3-jdk-8 as builder
RUN git clone https://github.com/wakaleo/game-of-life.git
RUN cd /game-of-life
WORKDIR /game-of-life
RUN mvn package
FROM tomcat:8
LABEL owner=none
EXPOSE 8080
COPY --from=builder /game-of-life/gameoflife-web/target/gameoflife.war /usr/local/tomcat/webapps/gameoflife.war
CMD ["catalina.sh", "run"]