opening OCI Ports for Docker Containers

  1. Comprehensive Blog on Dockers running on OCI
  2. running a Docker Container on OCI
  3. opening OCI Ports for Docker Containers
  4. Building a Docker Image by using Dockerfile
  5. Committing changes made in a Docker without using Dockerfile
  6. Pushing Docker Images to Docker Hub
  7. DevOps with Github, Docker Hub and Oracle Container Cloud Services
Goal

Goal of this session is to Run Tomcat Docker container in the background or as a Detached Mode with -d option

Download Docker Image Run Tomcat
[email protected]:~$ docker run -it -p 8888:8080 tomcat:latest
Unable to find image 'tomcat:latest' locally
latest: Pulling from library/tomcat
bc9ab73e5b14: Pull complete 
193a6306c92a: Pull complete 
e5c3f8c317dc: Pull complete 
d21441932c53: Pull complete 
fa76b0d25092: Pull complete 
346fd8610875: Pull complete 
3ca5d6af9022: Pull complete 
c06cfa2cea32: Pull complete 
205950a5a114: Pull complete 
6332a55c669e: Pull complete 
b5efe96df0e8: Pull complete 
b4e0e542b56a: Pull complete 
Digest: sha256:1fcb78083a88bc300d9fcb2ecfe4bcf1d20337db9196634c6c7a823bfc4da4ee
Status: Downloaded newer image for tomcat:latest
[email protected]:~$ docker run -it -d -p 8888:8080 tomcat:latest
d8e5454419c29ce7b5f5a99b67712474409c8a8c4e30782c2addf38b8c4ccd3c
[email protected]:~$ 
docker logs d8e5454419c29ce7b5f5a99b67712474409c8a8c4e30782c2addf38b8c4ccd3c
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /docker-java-home/jre
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
06-Nov-2018 11:44:05.799 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.34
06-Nov-2018 11:44:05.804 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Sep 4 2018 22:28:22 UTC
06-Nov-2018 11:44:05.804 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.34.0
06-Nov-2018 11:44:05.805 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
06-Nov-2018 11:44:05.805 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            4.15.0-36-generic
.....
[email protected]:~$ curl localhost:8888
YOU Should See Tomcat Home Page HTML
View Docker Logs
docker logs d8e5454419c29ce7b5f5a99b67712474409c8a8c4e30782c2addf38b8c4ccd3c
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /docker-java-home/jre
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
06-Nov-2018 11:44:05.799 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.34
06-Nov-2018 11:44:05.804 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          
....
open the OCI Port to access Tomcat from Public Internet

Lets now access the Security List of the VCN that the image is using an Open Port 8888

Reality Check

VM public ip address : 8888

Stopping the Container and Removing them
[email protected]:~$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                           PORTS                    NAMES
d8e5454419c2        tomcat:latest       "catalina.sh run"        About an hour ago   
Up About an hour                 0.0.0.0:8888->8080/tcp   zealous_bhaskara
8387b99fb6b3        tomcat:latest       "catalina.sh run"        About an hour ago   Exited (130) About an hour ago    
[email protected]:~$ docker rm d8e5454419c2
Error response from daemon: You cannot remove a running container d8e5454419c29ce7b5f5a99b67712474409c8a8c4e30782c2addf38b8c4ccd3c. Stop the container before attempting removal or force remove
[email protected]:~$ docker stop d8e5454419c2
d8e5454419c2
[email protected]:~$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                           PORTS               NAMES
d8e5454419c2        tomcat:latest       "catalina.sh run"        About an hour ago   Exited (143) 2 minutes ago                           zealous_bhaskara
8387b99fb6b3        tomcat:latest       "catalina.sh run"        About an hour ago   Exited (130) About an hour ago                       relaxed_lumiere
b00519b4ab91        busybox:latest      "sleep 100"              About an hour ago   Exited (0) About an hour ago                         jolly_torvalds
[email protected]:~$ docker rm d8e5454419c2
d8e5454419c2
Cleaning Up - Stopping and Removing all containers
[email protected]:~$ docker stop $(docker ps -a -q)
8387b99fb6b3
b00519b4ab91
a13c8f04b07b
f4d522488e00
6abd29b84824
4c0ebd734c27
c496b254dfd4
bca33f082ed2
cd396b2fde1d
[email protected]:~$ docker rm $(docker ps -a -q)
8387b99fb6b3
b00519b4ab91
a13c8f04b07b
f4d522488e00
6abd29b84824
4c0ebd734c27
c496b254dfd4
bca33f082ed2
cd396b2fde1d
[email protected]:~$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
..

Whats Next >> Building a Docker Image by using Dockerfile