1. Install docker. Use docker documentation.
2. Write a the docker file - refer
This is script we define what are the commands to run when initiating the container. This includes, some software instillations, environment variable setting, resource copying and main running program defining. It use a specific language and following are some of the meanings of the language syntax.
Meanings of commands
FROM - base image
RUN - to run commands in the terminal
ADD - Copy files
ENV - Setting environment variables
EXPOSE - ports to open
ENTRYPOINT - main program to run
eg: Following is a sample docker file which creates a container with java and tomcat installed and tomcat server started.
FROM ubuntu:14.04
MAINTAINER Dimuthu Upeksha <dimuthu@adroitlogic.com>
RUN apt-get update && apt-get install -y unzip
# Installing java
ADD jdk-7u75-linux-x64.tar.gz /opt
#RUN tar -xzf /tmp/jdk-7u75-linux-x64.tar.gz -C /opt
RUN ln -s /opt/jdk1.7.0_75 /opt/jdk
ADD UnlimitedJCEPolicyJDK7.zip /tmp/UnlimitedJCEPolicyJDK7.zip
RUN unzip /tmp/UnlimitedJCEPolicyJDK7.zip -d /opt
RUN cp /opt/UnlimitedJCEPolicy/*.jar /opt/jdk/jre/lib/security/
# Copying ultraesb binaries
ADD tomcat.tar.gz /opt
ADD start-tomcat.sh /opt/start-tomcat.sh
RUN rm -rf /tmp/*
ENV JAVA_HOME /opt/jdk
ENV PATH /opt/jdk/bin:$PATH
EXPOSE 1-65535
ENTRYPOINT /bin/bash -c "sh /opt/start-tomcat.sh && tail -100f /opt/apache-tomcat-7.0.29/logs/catalina.out" |
3. Build docker image
sudo docker build -t <image_name> // usual pattern, name/app_name:version
eg : sudo docker build -t amila/ultraesb:v1
4. Run docker image
sudo docker run -it<if u want a interactive console> --name <container name> <image_name>
eg : sudo docker run -it --name ultraesb dimuthuupe/ultraesb:v1 /bin/bash
sudo docker run -privileged -t -i dimuthuupe/ultraesb:v1 /bin/bash
After running this to check the created docker container use command 'docker ps' .
You can use the same image to create many containers with different names.
You can log in to the created container with command
docker exec -it <container_name> /bin/bash
sudo docker run -privileged -t -i dimuthuupe/ultraesb:v1 /bin/bash
After running this to check the created docker container use command 'docker ps' .
You can use the same image to create many containers with different names.
You can log in to the created container with command
docker exec -it <container_name> /bin/bash
5. Port mapping
sudo docker run -t -i -p 8080:8080 dimuthuupe/ultraesb:v1 /bin/bash
No comments:
Post a Comment