{"id":825,"date":"2022-11-25T18:53:49","date_gmt":"2022-11-25T18:53:49","guid":{"rendered":"http:\/\/wp.chaoyu.nl\/?p=825"},"modified":"2023-07-25T00:20:15","modified_gmt":"2023-07-24T22:20:15","slug":"docker-learning-notes","status":"publish","type":"post","link":"https:\/\/chaoyu.nl\/?p=825","title":{"rendered":"Docker learning notes: By Dockerise Oracle Database + APEX instance"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">How to fix docker: Got permission denied while trying to connect to the Docker daemon socket. Read more <a href=\"https:\/\/www.digitalocean.com\/community\/questions\/how-to-fix-docker-got-permission-denied-while-trying-to-connect-to-the-docker-daemon-socket\" data-type=\"URL\" data-id=\"https:\/\/www.digitalocean.com\/community\/questions\/how-to-fix-docker-got-permission-denied-while-trying-to-connect-to-the-docker-daemon-socket\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\"># To create the docker group and add your user:\nsudo groupadd docker\n# Add your user to the docker group\nsudo usermod -aG docker ${USER}\n#after, you most likely needs a reboot<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Images<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\"># to list all images\ndocker images\n# to romve an image\ndocker image rm ${image id}\n# to build an image with at current direct (the . at the end )\ndocker build -t ${tagname} . <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Volumes<\/h2>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\"># to create \ndocker volume create MY_VOLUME\n# to remove \ndocker volume rm MY_VOLUME\n# to list \ndocker volume ls\n# to inspect\ndocker volume inspect MY_VOLUME\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Container<\/h2>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">#list all container \ndocker ps -a\n#start bash from an running container \ndocker exec -it ${container id} \/bin\/bash\n#stop a container \ndocker stop ${container id}\n\n#start a container and run bash by adding bash at the end of the command\ndocker run -it -p 1521:1521 --name c01 with_data_pump:1.0.0 bash<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Tab into a running container&#8217;s cli<\/h2>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">docker attach ${container id}\ndocker exec -it ${container id} \/bin\/bash<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Leave container Bash session without killing the container<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Ctrl<\/code> + <code>P<\/code> then <code>Ctrl<\/code> + <code>Q<\/code> <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\" line-numbers\">#its called escape sequence<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Start a status &#8216;exited&#8217; container and tab into the bash<\/h2>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">docker start ${container id}\ndocker attach  ${container id}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">start a container with port mapping<\/h2>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\"># start a container detached and map host port 80 to container port 8080, give the container a custom name with image id \ndocker run -d -p 80:8080 --name ${container_name} ${image_id}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Create a new image with a running container where configuration are made <\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\"># list all containers\ndocker ps -a\n# find the one you are in and do a commit on its name or id , here i use the container name !!! the commit process can take a bit depends on the size of your container \ndocker commit practical_montalcini\n# or docker commit ${container_id} ${tag}:${version}\ndocker commit 857338c4ccf4 operation_image:3.0.0\n\n# after commit , find your newly created image and give it name \ndocker images # to show all images\n# tag to change the name \ndocker tag 3e70341ac6d9 oracle18_apex22_2_ords22\n# add tags to image\ndocker image tag oracle18_apex22_2_ords22:latest oracle18_apex22_2_ords22:1.0\n# remove latest tag\ndocker image remove oracle18_apex22_2_ords22:latest<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Create Oracle APEX Docker <\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211; Dockerfile to take the oraclelinux7 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211; Copy files into linux or use wget in oracle linux 7 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211; apex , ords, xe18 , java11, xe preinstall<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211; install XE pre install<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211; write <code><strong><em>export ORACLE_DOCKER_INSTALL=true<\/em><\/strong><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211; install XE<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211; Follow this official <a href=\"https:\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/18\/xeinl\/procedure-installing-oracle-database-xe.html\" data-type=\"URL\" data-id=\"https:\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/18\/xeinl\/procedure-installing-oracle-database-xe.html\" target=\"_blank\" rel=\"noreferrer noopener\">guide <\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211; Remeber to run the following comands on user oralce, read more <a href=\"https:\/\/community.oracle.com\/tech\/developers\/discussion\/4187145\/my-listener-is-not-starting-nl-00280\" data-type=\"URL\" data-id=\"https:\/\/community.oracle.com\/tech\/developers\/discussion\/4187145\/my-listener-is-not-starting-nl-00280\" target=\"_blank\" rel=\"noreferrer noopener\">here <\/a><\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">su - oracle \nexport ORACLE_SID=XE \nexport ORAENV_ASK=NO \n. \/opt\/oracle\/product\/18c\/dbhomeXE\/bin\/oraenv<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For 21xe, do a <code>\/etc\/init.d\/oracle-xe-21c start  <\/code> , this will trigger generate listener.ora and display its location. for 21xe , it is at<code> \/opt\/oracle\/homes\/OraDBHome21cXE\/network\/admin\/listener.ora<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">update with<strong> <em><code>nano \/opt\/oracle\/product\/18c\/dbhomeXE\/network\/admin\/listener.ora<\/code><\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\"># listener.ora Network Configuration File: \/opt\/oracle\/product\/18c\/dbhomeXE\/network\/admin\/listener.ora\n# Generated by Oracle configuration tools.\n\nDEFAULT_SERVICE_LISTENER = XE\n\nLISTENER =\n  (DESCRIPTION_LIST =\n    (DESCRIPTION =\n      (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))\n      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))\n    )\n  )<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">update \/opt\/oracle\/product\/18c\/dbhomeXE\/network\/admin\/tnsnames.ora. <a rel=\"noreferrer noopener\" href=\"https:\/\/stackoverflow.com\/questions\/67763676\/can-not-connect-to-oracle-outside-docker-container\" data-type=\"URL\" data-id=\"https:\/\/stackoverflow.com\/questions\/67763676\/can-not-connect-to-oracle-outside-docker-container\" target=\"_blank\">Here <\/a>are some explainations. Addtionally, here are two line of sql need to be remember <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">HOST = 0.0.0.0 # as well <\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">SQL&gt; alter session set container=XEPDB1; # to switch pdb;\nSQL&gt; show con_name  # to check current pdb;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Database wallet for Make Rest Calls <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>see <a rel=\"noreferrer noopener\" href=\"https:\/\/oracle-base.com\/articles\/misc\/utl_http-and-ssl\" data-type=\"URL\" data-id=\"https:\/\/oracle-base.com\/articles\/misc\/utl_http-and-ssl\" target=\"_blank\">here <\/a>create wallet folder and wallet  and <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/Dani3lSun\/oracle-ca-wallet-creator\" data-type=\"URL\" data-id=\"https:\/\/github.com\/Dani3lSun\/oracle-ca-wallet-creator\" target=\"_blank\">here<\/a> for wallets (make sure you are using oracle user , when create \/add certs into wallet)<\/li>\n\n\n\n<li>write this to change ownership of the wallet folder <\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\"> chown -R oracle:oinstall wallet\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">APEX installation, follow this <a rel=\"noreferrer noopener\" href=\"https:\/\/dsavenko.me\/oracledb-apex-ords-tomcat-httpd-centos7-all-in-one-guide-part-two\/\" data-type=\"URL\" data-id=\"https:\/\/dsavenko.me\/oracledb-apex-ords-tomcat-httpd-centos7-all-in-one-guide-part-two\/\" target=\"_blank\">Guide<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">my Dockerfile<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"docker\" class=\"language-docker line-numbers\">FROM operation_image:2.0.0\n\nCOPY .\/files\/*.sh \/root\/\n\nEXPOSE 1521 5500 8080\n\nCMD chmod +x \/root\/*.sh &amp;&amp; \\\n    bash \/root\/start_scripts.sh<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">my two file which is located in .\/files folder<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">start_scripts.sh<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">#!\/bin\/bash\necho \"#################################################\" &amp;&amp;\necho \"IN Oracle USER\" &amp;&amp;\necho \"#################################################\" &amp;&amp;\n\nsudo -i -u oracle bash &lt;&lt; EOF\nexport PATH=\/opt\/oracle\/jdk-11.0.16.1\/bin:\/opt\/oracle\/ords\/bin:\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin:\/opt\/oracle\/product\/18c\/dbhomeXE\/bin\n#export _JAVA_OPTIONS=\"-Xms1024M -Xmx1024M\"\nexport ORACLE_SID=XE\nexport ORAENV_ASK=NO\n. \/opt\/oracle\/product\/18c\/dbhomeXE\/bin\/oraenv\nEOF\n\necho \"#################################################\" &amp;&amp;\necho \"OUT Oracle User\" &amp;&amp;\necho \"Export Root Parameters\" &amp;&amp;\necho \"#################################################\" &amp;&amp;\n\nexport PATH=\/opt\/oracle\/jdk-11.0.16.1\/bin:\/opt\/oracle\/ords\/bin:\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin:\/opt\/oracle\/product\/18c\/dbhomeXE\/bin &amp;&amp;\nexport ORACLE_SID=XE &amp;&amp;\nexport ORAENV_ASK=NO &amp;&amp;\n. \/opt\/oracle\/product\/18c\/dbhomeXE\/bin\/oraenv &amp;&amp;\n\necho \"#################################################\" &amp;&amp;\necho \"start DB\" &amp;&amp;\necho \"#################################################\" &amp;&amp;\n\n\/etc\/init.d\/oracle-xe-18c start &amp;&amp;\n\necho \"#################################################\" &amp;&amp;\necho \"Database started\" &amp;&amp;\necho \"#################################################\" &amp;&amp;\n\n\necho \"#################################################\" &amp;&amp;\necho \"Run SQL Scripts here if any\" &amp;&amp;\necho \"#################################################\" &amp;&amp;\n\n\necho \"#################################################\" &amp;&amp;\necho \"start ORDS\" &amp;&amp;\necho \"#################################################\" &amp;&amp;\nbash \/root\/start_ords.sh<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">start_ords.sh<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">cd \/opt\/oracle\/config &amp;&amp; ords serve<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Kill Running container and spin a new one with Bash script<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">#!\/bin\/bash\n#_RUNNING_ID = $(docker ps -a -q)\n#echo $_RUNNING_ID &amp;&amp;\n\nif [ ! -z \"$(docker ps -a -q)\" ]\nthen\n echo \"#######################################################\"&amp;&amp;\n echo \"Running Container Found: $(docker ps -a -q)\" &amp;&amp;\n echo \"#######################################################\"&amp;&amp;\n echo \"Destroying $(docker ps -a -q)\" &amp;&amp;\n docker stop $(docker ps -a -q) &amp;&amp;\n docker rm $(docker ps -a -q)\n echo \".\" &amp;&amp;\n echo \".\" &amp;&amp;\n echo \".\" &amp;&amp;\n echo \".\" &amp;&amp;\n echo \".\" &amp;&amp;\n echo \"#######################################################\"&amp;&amp;\n echo \"Run Container with Latest Image\" &amp;&amp;\n echo \"#######################################################\"&amp;&amp;\n docker run -d -p 1521:1521 -p 8080:8080 --name c01 operation_image:2.0.0\n echo \"#######################################################\"&amp;&amp;\n echo \"PING APEX webserver to check if all online before release control to Jenkins\"\n while [[ $(curl -Is localhost:8080 | head -1) != *\"HTTP\"* ]]\n do\n   echo $(curl -Is localhost:8080 | head -1)\n   echo \"Server is not online, sleep for 5 seconds and try again\"\n   sleep 1\n   echo \"....\"\n   sleep 1\n   echo \"....\"\n   sleep 1\n   echo \"....\"\n   sleep 1\n   echo \"....\"\n   sleep 1\n   echo \"....\"\n done\n echo \"All services are ready, release control to Jenkins\"\nelse\n echo \"#######################################################\"&amp;&amp;\n echo \"NO Running \/ Exited Container Found\" &amp;&amp;\n echo \"#######################################################\"&amp;&amp;\n echo \".\" &amp;&amp;\n echo \".\" &amp;&amp;\n echo \".\" &amp;&amp;\n echo \".\" &amp;&amp;\n echo \".\" &amp;&amp;\n echo \"#######################################################\"&amp;&amp;\n echo \"Run Container with Latest Image\" &amp;&amp;\n echo \"#######################################################\"&amp;&amp;\n docker run -d -p 1521:1521 -p 8080:8080 --name c01 operation_image:2.0.0\n while [[ $(curl -Is localhost:8080 | head -1) != *\"HTTP\"* ]]\n do\n   echo $(curl -Is localhost:8080 | head -1)\n   echo \"Server is not online, sleep for 5 seconds and try again\"\n   sleep 1\n   echo \"....\"\n   sleep 1\n   echo \"....\"\n   sleep 1\n   echo \"....\"\n   sleep 1\n   echo \"....\"\n   sleep 1\n   echo \"....\"\n done\n echo \"All services are ready, release control to Jenkins\"\nfi<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>How to fix docker: Got permission denied while trying to connect to the Docker daemon socket. Read more here. Images Volumes Container Tab into a running container&#8217;s cli Leave container Bash session without killing the container Ctrl + P then Ctrl + Q Start a status &#8216;exited&#8217; container and tab into the bash start a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":828,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54,17],"tags":[],"class_list":["post-825","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker","category-linux"],"_links":{"self":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=825"}],"version-history":[{"count":48,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/825\/revisions"}],"predecessor-version":[{"id":1348,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/825\/revisions\/1348"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/media\/828"}],"wp:attachment":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}