{"id":1882,"date":"2017-04-25T17:08:52","date_gmt":"2017-04-25T15:08:52","guid":{"rendered":"http:\/\/blog.rabahi.net\/?page_id=1882"},"modified":"2017-04-25T17:23:40","modified_gmt":"2017-04-25T15:23:40","slug":"docker-create-cluster","status":"publish","type":"page","link":"https:\/\/blog.rabahi.net\/?page_id=1882","title":{"rendered":"Docker create service"},"content":{"rendered":"<h2>First let&#8217;s create a tomcat app<\/h2>\n<p>Create file &#8216;Dockerfile&#8217; with the following content<\/p>\n<pre>\r\n# Use an official image of centos\r\nFROM centos\r\n\r\n# Download and install tomcat\r\nRUN yum -y install wget\r\nRUN mkdir -p \/opt\/java\r\nRUN wget -O \/opt\/java\/apache-tomcat-8.5.14.tar.gz http:\/\/apache.crihan.fr\/dist\/tomcat\/tomcat-8\/v8.5.14\/bin\/apache-tomcat-8.5.14.tar.gz\r\nRUN cd \/opt\/java && tar xvfz apache-tomcat-8.5.14.tar.gz\r\nRUN ln -s \/opt\/java\/apache-tomcat-8.5.14 \/opt\/java\/apache-tomcat\r\nRUN yum -y install java-1.8.0-openjdk \r\n\r\n# Set the working directory to $CATALINA_HOME\r\nENV CATALINA_HOME \/opt\/java\/apache-tomcat\r\nENV PATH $CATALINA_HOME\/bin:$PATH\r\nWORKDIR $CATALINA_HOME\r\n\r\n# Make port 8080 available to the world outside this container\r\nEXPOSE 8080\r\n\r\n# Run catalina.sh when container launches\r\nCMD [\"catalina.sh\", \"run\"]\r\n<\/pre>\n<p>And create my tomcat app:<\/p>\n<pre lang=\"bash\">\r\ndocker build -t centos-tomcat85 .\r\n<\/pre>\n<p>Now you can test it, run the command<\/p>\n<pre lang=\"bash\">\r\ndocker run -p 1234:8080 centos-tomcat85 .\r\n<\/pre>\n<p>And meet you here : http:\/\/localhost:1234<\/p>\n<h2>Now let&#8217;s create our service<\/h2>\n<p>Create file &#8216;docker-compose.yml&#8217; with the following content<\/p>\n<pre>\r\nversion: \"3\"\r\nservices:\r\n  web:\r\n    image: centos-tomcat85:latest\r\n    deploy:\r\n      replicas: 2\r\n      resources:\r\n        limits:\r\n          cpus: \"0.5\"\r\n          memory: 500M\r\n      restart_policy:\r\n        condition: on-failure\r\n    ports:\r\n      - \"80:8080\"\r\n    networks:\r\n      - webnet\r\nnetworks:\r\n  webnet:\r\n<\/pre>\n<p>Note : <\/p>\n<ul>\n<li>we are mapping container port 8080 to external port 80<\/li>\n<li>we deploy 2 load balanced services<\/li>\n<\/ul>\n<p>Init swarm :<\/p>\n<pre lang=\"bash\">\r\ndocker swarm init\r\n<\/pre>\n<p>And deploy the service<\/p>\n<pre lang=\"bash\">\r\ndocker stack deploy -c docker-compose.yml centos-tomcat85\r\n<\/pre>\n<p>Now you can test it, run the command<\/p>\n<pre lang=\"bash\">\r\ndocker stack ps centos-tomcat85\r\n<\/pre>\n<p>And meet you here : http:\/\/localhost<\/p>\n<p>To stop the app :<\/p>\n<pre lang=\"bash\">\r\ndocker stack rm centos-tomcat85\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>First let&#8217;s create a tomcat app Create file &#8216;Dockerfile&#8217; with the following content # Use an official image of centos FROM centos # Download and install tomcat RUN yum -y install wget RUN mkdir -p \/opt\/java RUN wget -O \/opt\/java\/apache-tomcat-8.5.14.tar.gz http:\/\/apache.crihan.fr\/dist\/tomcat\/tomcat-8\/v8.5.14\/bin\/apache-tomcat-8.5.14.tar.gz RUN cd \/opt\/java &#038;&#038; tar xvfz apache-tomcat-8.5.14.tar.gz RUN ln -s \/opt\/java\/apache-tomcat-8.5.14 \/opt\/java\/apache-tomcat RUN yum [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1857,"menu_order":4,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1882","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1882","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1882"}],"version-history":[{"count":5,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1882\/revisions"}],"predecessor-version":[{"id":1887,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1882\/revisions\/1887"}],"up":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1857"}],"wp:attachment":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}