Wednesday, December 30, 2015

DevOps Docker

Intoduction Docker :

Docker is an open platform for developing, shipping, and running applications. Docker is designed to deliver your applications faster. With Docker you can separate your applications from your infrastructure and treat your infrastructure like a managed application. Docker helps you ship code faster, test faster, deploy faster, and shorten the cycle between writing code and running code.

Install Docker in ubuntu ...

Building Image From a Dockerfile


Example Dokerfile :

1- install jdk
2- install apache-tomcat
3- deploy application 

###########################
FROM ubuntu
MAINTAINER kallel wassim <kallel.wassim@gmail.com>
RUN mkdir -p /opt/programs/sample-docker
COPY apache-tomcat-8.0.28.tar.gz  /opt/programs/sample-docker/
WORKDIR /opt/programs/sample-docker
RUN tar -xzf apache-tomcat-8.0.28.tar.gz
RUN rm /opt/programs/sample-docker/apache-tomcat-8.0.28.tar.gz
COPY MyApp.war /opt/programs/sample-docker/apache-tomcat-8.0.28/webapps/
ADD server.xml /opt/programs/sample-docker/apache-tomcat-8.0.28/conf/
COPY jdk-8u45-linux-x64.tar.gz /opt/programs/sample-docker/
WORKDIR /opt/programs/sample-docker
RUN tar -xzf jdk-8u45-linux-x64.tar.gz
RUN rm /opt/programs/sample-docker/jdk-8u45-linux-x64.tar.gz
ENV JAVA_HOME /opt/programs/sample-docker/jdk1.8.0_45
ENV PATH ${PATH}:${JAVA_HOME}/bin
EXPOSE 8080
CMD /opt/programs/sample-docker/apache-tomcat-8.0.28/bin/catalina.sh start

###############

Dockerfile description command

Instruction Description
FROM This must be the first instruction in the Dockerfile and identifies the image to inherit from.
MAINTAINER Provides visibility and credit to the author of the image
RUN Executes a Linux command for configuring and installing
ENTRYPOINT The final script or application used  to bootstrap the container, making it an executable application
CMD Provide default arguments to the ENTRYPOINT using a JSON array format
LABEL Name/value metadata about the image
ENV Sets environment variables
COPY Copies files into the container
ADD Alternative to copy
WORKDIR Sets working directory for RUN, CMD, ENTRYPOINT, COPY, and/or ADD instructions
EXPOSE Ports the container will listen on
VOLUME Creates a mount point
USER User to run RUN, CMD, and/or ENTRYPOINT instructions



Building & Running image

To build this image from the directory containing the Dockerfile, run the
following command:

docker build -t  java_ee/sample_java_ee .


to run this image

docker run -t java_ee/sample_java_ee

http://127.0.0.1:8080/MyApp/


Test running container

docker ps -l

CONTAINER ID        IMAGE                           COMMAND                CREATED             STATUS                     PORTS               NAMES
6c292075af88        java_ee/sample_java_ee:latest   "/bin/sh -c '/opt/pr   7 seconds ago       Exited (0) 6 seconds ago                       jolly_sinoussi     


 Starting & Stoping image

#to start image

docker start sample_java_ee

#to stop image

docker stop sample_java_ee

Push image to Repository

Now push your image using the push command, specifying your username, image name, and version number.

docker push java_ee/sample_java_ee


Architecture DevOps Docker solution










No comments:

Post a Comment