{"id":7803,"date":"2019-04-23T17:37:11","date_gmt":"2019-04-23T09:37:11","guid":{"rendered":"http:\/\/rmohan.com\/?p=7803"},"modified":"2019-04-23T17:37:13","modified_gmt":"2019-04-23T09:37:13","slug":"docker-installation-builds-tomcat-mysql","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7803","title":{"rendered":"Docker installation builds Tomcat + MySQL"},"content":{"rendered":"\n<p>Docker installation builds Tomcat + MySQL<\/p>\n\n\n\n<p>virtual machine<br>\nVirtual machine installation Docker<br>\nBuild on a clean CentOS image<br>\nCentos image preparation<br>\nPull the Centos image on the virtual machine: docker pull centos<br>\nCreate a container to run the Centos image: docker run -it -d &#8211;name mycentos centos \/bin\/bash<br>\nNote: There is an error here [ WARNING: IPv4 forwarding is disabled. Networking will not work. ]<\/p>\n\n\n\n<p>Change the virtual machine file: vim \/usr\/lib\/sysctl.d\/00-system.conf<br>\nAdd the following content<br>\nnet.ipv4.ip_forward=1<br>\nRestart the network: systemctl restart network<br>\nNote: There is another problem here, systemctl in docker can not be used normally. Find the following solutions on the official website<\/p>\n\n\n\n<p>Link: https:\/\/forums.docker.com\/t\/systemctl-status-is-not-working-in-my-docker-container\/9075\/4<\/p>\n\n\n\n<p>Run mirror with the following statement<br>\ndocker run &#8211;privileged  -v \/sys\/fs\/cgroup:\/sys\/fs\/cgroup -it -d &#8211;name usr_sbin_init_centos centos \/usr\/sbin\/init<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">1. Must have &#8211;privileged<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\">2. Must have -v \/sys\/fs\/cgroup:\/sys\/fs\/cgroup<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\">3. Replace bin\/bash with \/usr\/sbin\/init<\/h1>\n\n\n\n<p>Finally, I was able to run a Centos image.<\/p>\n\n\n\n<p>Install the JAVA environment<br>\nPrepare the JDK tarball to upload to the virtual machine<br>\nPut the tarball into the docker container using docker cp<br>\ndocker cp  jdk-11.0.2_linux-x64_bin.tar.gz 41dbc0fbdf3c:\/<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">The same as the linux cp specified usage, you need to add the identifier of the container: id or name<\/h1>\n\n\n\n<p>Extract the tar package<br>\ntar -xf jdk-11.0.2_linux-x64_bin.tar.gz  -C \/usr\/local\/java\/jdk<br>\nEdit profile file export java environment variable<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\/etc\/profile<\/h1>\n\n\n\n<p>export JAVA_HOME=\/usr\/local\/java\/jdk\/jdk1.8.0_91<br>\nexport PATH=$JAVA_HOME\/bin:$PATH<br>\nexport CLASSPATH=.:$JAVA_HOME\/lib\/dt.jar:$JAVA_HOME\/lib\/tools.jar<br>\nRun source \/etc\/profile to make environment variables take effect<br>\nWhether the test is successful<br>\njava &#8211;version <\/p>\n\n\n\n<h1 class=\"wp-block-heading\">result<\/h1>\n\n\n\n<p>java 11.0.2 2019-01-15 LTS<br>\nJava(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)<br>\nJava HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)<br>\nInstall Tomcat<br>\nPrepare the tomcat tar package to upload to the virtual machine and cp to the docker container<br>\nExtract to<br>\ntar -xf apache-tomcat-8.5.38.tar.gz  -C \/usr\/local\/tomcat<br>\nSet boot boot, by using rc.local file<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">rc.local Add the following code<\/h1>\n\n\n\n<p>export JAVA_HOME=\/usr\/local\/java\/jdk\/jdk-11.0.2<br>\n\/usr\/local\/tomcat\/apache-tomcat-8.5.38\/bin\/startup.sh<br>\nOpen tomcat<br>\n\/usr\/local\/tomcat\/apache-tomcat-8.5.38\/bin\/ directory running<br>\n.\/startup.sh<br>\nDetection<br>\ncurl localhost:8080<\/p>\n\n\n\n<p>Install mysql<br>\nGet the yum source of mysql<br>\n wget -i -c http:\/\/dev.mysql.com\/get\/mysql57-community-release-el7-10.noarch.rpm<br>\nInstall the above yum source<br>\nyum -y install mysql57-community-release-el7-10.noarch.rpm<br>\nYum install mysql<br>\nyum -y install mysql-community-server<br>\nChange the mysql configuration: \/etc\/my\/cnf<br>\nValidate_password=OFF # Turn off password verification<br>\ncharacter-set-server=utf8 <br>\ncollation-server=utf8_general_ci<br>\nlog-error=\/var\/log\/mysqld.log <br>\npid-file=\/var\/run\/mysqld\/mysqld.pid<br>\nInitialize specified but the data directory has files in it # The default behavior of timestamp from 5.6 is already deprecated, need to close the warning<br>\n<\/p>\n\n\n<p>[client]<\/p>\n\n\n\n<p>\ndefault-character-set=utf8<br>\nGet the mysql initial password<br>\ngrep &#8220;password&#8221; \/var\/log\/mysqld.log\n<\/p>\n\n\n\n<p>[Note] A temporary password is generated for root@localhost: k:nT&lt;dT,t4sF<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Use this password to log in to mysql<\/h1>\n\n\n\n<p>Go to mysql and proceed<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Enter<\/h1>\n\n\n\n<p>mysql -u root -p <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">change the password<\/h4>\n\n\n\n<p>ALTER USER &#8216;root&#8217;@&#8217;localhost&#8217; IDENTIFIED BY &#8216;111111&#8217;;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Change to make mysql remote access<\/h4>\n\n\n\n<p>update user set host = &#8216;%&#8217; where user = &#8216;root&#8217;;<br>\nTest, you can use physical machine, use navicat to access mysql in docker<br>\nPacking container<br>\nOn the docker hub<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Submit the container as a mirror<\/h4>\n\n\n\n<p>docker commit -a &#8216;kane&#8217; -m &#8216;test&#8217; container_id images_name:images_tag<\/p>\n\n\n\n<p>dockerhub<br>\ndocker push kane0725\/tomcat<br>\nLocal tarball everywhere<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Export to cost tar package<\/h4>\n\n\n\n<p>docker export -o test.tar a404c6c174a2<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Import the tar package into a mirror<\/h4>\n\n\n\n<p>docker import test.tar test_images<br>\nUse Dockerfile<br>\nNote: only build a mirror of tomcat<\/p>\n\n\n\n<p>Ready to work<br>\nCreate a special folder and put the jdk and tomcat tarballs<br>\nCreate a Dockerfile in this directory<br>\nCentos base image<br>\ndocument content<br>\nFROM centos<br>\nMAINTAINER tomcat mysql<br>\nADD jdk-11.0.2 \/usr\/local\/java<br>\nENV JAVA_HOME \/usr\/local\/java\/<br>\nADD apache-tomcat-8.5.38 \/usr\/local\/tomcat8<br>\nEXPOSE 8080<br>\nOutput results using docker build<br>\n<\/p>\n\n\n<p>[root@localhost dockerfile]<\/p>\n\n\n\n<p># docker build -t tomcats:centos .<br>\nSending build context to Docker daemon 505.8 MB<br>\nStep 1\/7 : FROM centos<br>\n &#8212;&gt; 1e1148e4cc2c<br>\nStep 2\/7 : MAINTAINER tomcat mysql<br>\n &#8212;&gt; Using cache<br>\n &#8212;&gt; 889454b28f55<br>\nStep 3\/7 : ADD jdk-11.0.2 \/usr\/local\/java<br>\n &#8212;&gt; Using cache<br>\n &#8212;&gt; 8cad86ae7723<br>\nStep 4\/7 : ENV JAVA_HOME \/usr\/local\/java\/<br>\n &#8212;&gt; Running in 15d89d66adb4<br>\n &#8212;&gt; 767983acfaca<br>\nRemoving intermediate container 15d89d66adb4<br>\nStep 5\/7 : ADD apache-tomcat-8.5.38 \/usr\/local\/tomcat8<br>\n &#8212;&gt; 4219d7d611ec<br>\nRemoving intermediate container 3c2438ecf955<br>\nStep 6\/7 : EXPOSE 8080<br>\n &#8212;&gt; Running in 56c4e0c3b326<br>\n &#8212;&gt; 7c5bd484168a<br>\nRemoving intermediate container 56c4e0c3b326<br>\nStep 7\/7 : RUN \/usr\/local\/tomcat8\/bin\/startup.sh<br>\n &#8212;&gt; Running in 7a73d0317db3\n<\/p>\n\n\n\n<p>Tomcat started.<br>\n &#8212;&gt; b53a6d54bf64<br>\nRemoving intermediate container 7a73d0317db3<br>\nSuccessfully built b53a6d54bf64<br>\nDocker build problem<br>\nBe sure to bring the order behind. Otherwise it will report an error.<br>\n&#8220;docker build&#8221; requires exactly 1 argument(s).<br>\nRun a container<\/p>\n\n\n\n<p>docker run -it &#8211;name tomcats &#8211;restart always -p 1234:8080 tomcats \/bin\/bash<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">tomcat startup.sh<\/h4>\n\n\n\n<p>\/usr\/local\/tomcat8\/bin\/startup.sh<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">result<\/h4>\n\n\n\n<p>Using CATALINA_BASE:   \/usr\/local\/tomcat8<br>\nUsing CATALINA_HOME:   \/usr\/local\/tomcat8<br>\nUsing CATALINA_TMPDIR: \/usr\/local\/tomcat8\/temp<br>\nUsing JRE_HOME:        \/usr\/local\/java\/<br>\nUsing CLASSPATH:       \/usr\/local\/tomcat8\/bin\/bootstrap.jar:\/usr\/local\/tomcat8\/bin\/tomcat-juli.jar<br>\nTomcat started.<br>\nUse docker compose<br>\nInstall docker compose<br>\nOfficial: https:\/\/docs.docker.com\/compose\/install\/<\/p>\n\n\n\n<p>The way I choose is pip installation<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">installation<\/h4>\n\n\n\n<p>pip install docker-compose<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><\/h3>\n\n\n\n<p>docker-compose &#8211;version<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/h1>\n\n\n\n<p>docker-compose version 1.23.2, build 1110ad0<br>\nWrite docker-compose.yml<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">This yml file builds a mysql a tomcat container<\/h3>\n\n\n\n<p>version: &#8220;3&#8221;   <br>\nservices:<br>\n  mysql:<br>\n    container_name: mysql<br>\n    image: mysql:5.7                          <br>\n    restart: always<br>\n    volumes:<br>\n      &#8211; .\/mysql\/data\/:\/var\/lib\/mysql\/                             <br>\n      &#8211; .\/mysql\/conf\/:\/etc\/mysql\/mysql.conf.d\/<br>\n    ports:<br>\n      &#8211; &#8220;6033:3306&#8221;<br>\n    environment:<br>\n      &#8211; MYSQL_ROOT_PASSWORD=<br>\n  tomcat:<br>\n    container_name: tomcat<br>\n    restart: always<br>\n    image: tomcat<br>\n    ports:<br>\n      &#8211; 8080:8080<br>\n      &#8211; 8009:8009<br>\n    links:<br>\n      &#8211; mysql:m1 #Connect to database mirroring<br>\nNote:<\/p>\n\n\n\n<p>Volumn must be a path, you cannot specify a file<\/p>\n\n\n\n<p>Tomcat specifies that the external conf has been created unsuccessfully, do not know why, prompt<\/p>\n\n\n\n<p>tomcat    | Feb 20, 2019 2:23:29 AM org.apache.catalina.startup.Catalina load<br>\ntomcat    | WARNING: Unable to load server configuration from [\/usr\/local\/tomcat\/conf\/server.xml]<br>\ntomcat    | Feb 20, 2019 2:23:29 AM org.apache.catalina.startup.Catalina start<br>\ntomcat    | SEVERE: Cannot start server. Server instance is not configured.<br>\ntomcat exited with code 1<br>\nRun command<br>\nNote: Must be executed under the directory of the yml file<\/p>\n\n\n\n<p>docker-compose up -d<\/p>\n\n\n\n<p>&#8212;&#8212;&#8212;-View docker container&#8212;&#8212;-<br>\n<\/p>\n\n\n<p>[root@localhost docker-compose]<\/p>\n\n\n\n<p># docker ps -a<br>\nCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                           PORTS                                             NAMES<br>\n1a8a0165a3a8        tomcat              &#8220;catalina.sh run&#8221;        7 seconds ago       Up 6 seconds                     0.0.0.0:8009-&gt;8009\/tcp, 0.0.0.0:8080-&gt;8080\/tcp    tomcat<br>\nddf081e87d67        mysql:5.7           &#8220;docker-entrypoint\u2026&#8221;   7 seconds ago       Up 7 seconds                     33060\/tcp, 0<\/p>\n","protected":false},"excerpt":{"rendered":"\n<p>Docker installation builds Tomcat + MySQL<\/p>\n<p>virtual machine Virtual machine installation Docker Build on a clean CentOS image Centos image preparation Pull the Centos image on the virtual machine: docker pull centos Create a container to run the Centos image: docker run -it -d &#8211;name mycentos centos \/bin\/bash Note: There is an error here [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7803"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7803"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7803\/revisions"}],"predecessor-version":[{"id":7804,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7803\/revisions\/7804"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}