❌

Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

Docker Ep 8: Tomcat: Exploring Docker Port Mapping and Logs

15 August 2024 at 09:32

Caution: We are just starting from basics. Even if you don’t understand below concepts there is no problem.

In our previous adventures, we’ve dabbled in Docker’s mysterious arts, running containers, inspecting them, and even detaching them to roam in the background.

Today, we’re stepping up our game by diving into Docker port mapping and the powerful docker logs command. And what better companion for this journey than the Tomcat image, a trusty open-source web server that brings Java servlets to life?

Summoning the Tomcat Image

To begin, we need to summon our new ally: the Tomcat image. Tomcat is a legendary web server that, by default, operates on port 8080 within its container. But what if we want to make this web server accessible to the outside world through a different port? This is where Docker’s port mapping comes into play.

First, let’s visit the Docker Hub and search for the Tomcat image. Once there, we can see that Tomcat will run on port 8080 by default. We’ll need to expose this port and map it to a port on our host machine using the -p option.

Port Mapping: Connecting the Container to the World

Docker port mapping allows us to make the services inside our container accessible from the outside world by forwarding a host port to a container port. The syntax for port mapping is:

-p <host_port>:<container_port>

For example, let’s say we want to map port 8080 inside the container to port 8888 on our host machine. This means that when we access port 8888 on our host, we’ll actually be talking to port 8080 inside the Tomcat container.

Let’s see this in action.

Running Tomcat with Port Mapping

Fire up your Docker terminal, make sure the font size is nice and large, and enter the following command:

docker run -it -p 8888:8080 tomcat:8.0

Here’s what’s happening:

  • -it runs the container interactively.
  • -p 8888:8080 maps port 8080 inside the container to port 8888 on our host.
  • tomcat:8.0 specifies the Tomcat image and its version.

Now, sit back and relax (or maybe grab a coffee) as Docker pulls down the Tomcat image. It’s about 300 MB, so depending on your internet connection, this might take a moment.

Once the image is downloaded, Docker will spin up the container, and our Tomcat server will be ready to roll.

Accessing the Tomcat Server

With the Tomcat container up and running, we can access the Tomcat web server through our web browser. But first, we need to know where to find it.

If you’re running Docker on Linux, or using Docker for Mac or Windows, the host IP is simply localhost. If you’re using Docker Machine, you’ll need to grab the IP address of the Docker Machine.

Now, open up your browser, type in localhost:8888 (or your Docker Machine’s IP address followed by :8888), and hit Enter.

The Tomcat console page should greet you warmly.

Running Tomcat in Detached Mode

While running a container in the foreground is great for testing, in production, we typically want our containers to run in the background. For this, we use the -d flag to run the container in detached mode.

Let’s modify our previous command to run Tomcat in the background:

docker run -d -p 8888:8080 tomcat:8.0

After hitting Enter, Docker will return a long container ID, confirming that Tomcat is now running in the background, silently serving up Java servlets.

Checking Container Status with docker ps -a

Curious about the status of your Tomcat container? Use the docker ps -a command to list all the containers on your system, including those that have exited. This is a handy way to check if your container is still running or if it has quietly exited.

docker ps -a

Reading the Tea Leaves: docker logs

Sometimes, you want to peek into the inner workings of your running containers to see what they’re up to. This is where the docker logs command comes in. It lets you view the logs generated by your container, which can be incredibly useful for debugging or just keeping an eye on things.

Let’s say you want to check the logs of your running Tomcat container. You would run:

docker logs <container_id>

There is more on docker logs, we shall see later.

Features of Java

By: Elavarasu
7 March 2024 at 14:40

1. Java is simple:

Java is a simple programming language. Because syntax is derived from C & C++ language. Java has removed some complex topics like Pointers, Operator Overloading, and Multiple Inheritance explicit memory allocation. Java has an Automatic Garbage Collection.

2. Java is Robust :

  • Java is Robust which means Strong | Reliable
  • It uses strong memory management.
  • Java provides automatic garbage collection which runs on the JVM to get rid of objects that are not being used by a Java application anymore.
  • There is exception handling and the type checking mechanism in Java
  • It is developed in such a way that it puts a lot of effort into checking errors as early as possible, which is why the Java compiler can detect even those errors that are not easy to detect by another programming language.

3. Java is Platform Independent :

Operating System – Os is interface between Human Being and Machine. Platform is nothing but Processor + Os .

  • Java has two level translation – Compilation and Interpretation.
  • Java Development Kit – JDK
  • Compiler is the part of jdk. Error checking mechanism is also present in jdk.
  • First jdk will check the error. If in case error is present in the code compilation is not allowed. So translator need error free file for translation process.
  • .Java file is converted into .classfile using JDK. It will check whole file into single run. Classfile is otherwise called Bytecode.
  • This byte code or .Classfile is Platform Independent code. Because .classfile is common for all the Platform(Os).
  • Java virtual machine – JVM . Jit compiler is part of JVM
  • JVM is part of JRE – Java Runtime Environment.
  • .Class file is converted into binary code using interpreter. It will check line by line. Binary code is otherwise known as Machine code.
  • This compilation is Platform Dependent conversion.
  • Jit compiler : Just in time compiler. Converting Byte code into Binary code.

Reference :

https://www.geeksforgeeks.org/java

https://www.javatpoint.com/features-of-java

Features of Java

By: Elavarasu
7 March 2024 at 14:40

1. Java is simple:

Java is a simple programming language. Because syntax is derived from C & C++ language. Java has removed some complex topics like Pointers, Operator Overloading, and Multiple Inheritance explicit memory allocation. Java has an Automatic Garbage Collection.

2. Java is Robust :

  • Java is Robust which means Strong | Reliable
  • It uses strong memory management.
  • Java provides automatic garbage collection which runs on the JVM to get rid of objects that are not being used by a Java application anymore.
  • There is exception handling and the type checking mechanism in Java
  • It is developed in such a way that it puts a lot of effort into checking errors as early as possible, which is why the Java compiler can detect even those errors that are not easy to detect by another programming language.

3. Java is Platform Independent :

Operating System – Os is interface between Human Being and Machine. Platform is nothing but Processor + Os .

  • Java has two level translation – Compilation and Interpretation.
  • Java Development Kit – JDK
  • Compiler is the part of jdk. Error checking mechanism is also present in jdk.
  • First jdk will check the error. If in case error is present in the code compilation is not allowed. So translator need error free file for translation process.
  • .Java file is converted into .classfile using JDK. It will check whole file into single run. Classfile is otherwise called Bytecode.
  • This byte code or .Classfile is Platform Independent code. Because .classfile is common for all the Platform(Os).
  • Java virtual machine – JVM . Jit compiler is part of JVM
  • JVM is part of JRE – Java Runtime Environment.
  • .Class file is converted into binary code using interpreter. It will check line by line. Binary code is otherwise known as Machine code.
  • This compilation is Platform Dependent conversion.
  • Jit compiler : Just in time compiler. Converting Byte code into Binary code.

Reference :

https://www.geeksforgeeks.org/java

https://www.javatpoint.com/features-of-java

Id | Sudo | Su

By: Elavarasu
29 February 2024 at 13:58

To know the user is using id command

id username

sudo

permits the user to execute a command as a super user at the admin level


su

su --> switch user
su -username
id
exit

Zip

zip filename file
zip filename *.txt
zip -sf filename.zip
to view the zipped file.

unzip

unzip filename 

to make another directory to unzip the file or rename the exisisting file.


ulimit

to manage the resources of the particular user.

ulimit -a

soft limit cannot more than hard limit

cat  /etc/security/limits.conf

type> can have the two values:

-β€œsoft” for enforcing the soft limits

– β€œhard” for enforcing hard limits


type

to know where the command it will present

type command

which 

where the command will locate

which mv


whatis

to know the description of the command


whereis

locate the binary, source, and manual page files for a command


apropos

search the manual page names and descriptions


change attribute

which makes the file unchangeable in the same location. but will copy the file in another location and edit the file.

sudo chattr +i filename
lsattr
sudo chattr -i file

it will convert unchangeable file to changeable file

sudo chattr -R +i dir1
sudo chattr -R -i dir1

to change the directory to unmutable


pid | pwdx

By: Elavarasu
29 February 2024 at 08:06
pidof ---> find the process ID of running program
vi test --> new process
ps -ef | grep vi
pidof vi
pwdx 8279
to know the present working directory of vi using pid.

nice value

NI –> (-20 to 19) highest priority to lowest priority range.

1 to 19 –> non root users will aslo set the ni values

-20 to -1 –> root user only set the value

to modify the program priority.
ps -l --> process list
to change the priority of the running program
nice -n 11 ps -l

renice

changing the priority of the running program.


user-management

useradd

create a new user or update default new user information.

tail /etc/passwd –> userslist

adduser –> adduser, addgroup – add a user or group to the system

sudo passwd sample
to set a password for sample user.
sudo passwd -Sa
to check all the users having password or not.
set a password for the sample user

after setting the passwd for sample user

sudo passwd -d sample
d --> delete
NP --> no passwd

user-delete

sudo userdel sample
sudo userdel -r sample --> to delete with home

Group

to create group with user

to create a group

addgroup :

deletegroup :

sudo groupdel groupname
sudo delgroup groupname
sudo usermod -aG sudo username
permission to using i commands for new user
to give sudo or root previlage for new user.

Id | Sudo | Su

By: Elavarasu
29 February 2024 at 13:58

To know the user is using id command

id username

sudo

permits the user to execute a command as a super user at the admin level


su

su --> switch user
su -username
id
exit

Zip

zip filename file
zip filename *.txt
zip -sf filename.zip
to view the zipped file.

unzip

unzip filename 

to make another directory to unzip the file or rename the exisisting file.


ulimit

to manage the resources of the particular user.

ulimit -a

soft limit cannot more than hard limit

cat  /etc/security/limits.conf

type> can have the two values:

-β€œsoft” for enforcing the soft limits

– β€œhard” for enforcing hard limits


type

to know where the command it will present

type command

which 

where the command will locate

which mv


whatis

to know the description of the command


whereis

locate the binary, source, and manual page files for a command


apropos

search the manual page names and descriptions


change attribute

which makes the file unchangeable in the same location. but will copy the file in another location and edit the file.

sudo chattr +i filename
lsattr
sudo chattr -i file

it will convert unchangeable file to changeable file

sudo chattr -R +i dir1
sudo chattr -R -i dir1

to change the directory to unmutable


pid | pwdx

By: Elavarasu
29 February 2024 at 08:06
pidof ---> find the process ID of running program
vi test --> new process
ps -ef | grep vi
pidof vi
pwdx 8279
to know the present working directory of vi using pid.

nice value

NI –> (-20 to 19) highest priority to lowest priority range.

1 to 19 –> non root users will aslo set the ni values

-20 to -1 –> root user only set the value

to modify the program priority.
ps -l --> process list
to change the priority of the running program
nice -n 11 ps -l

renice

changing the priority of the running program.


user-management

useradd

create a new user or update default new user information.

tail /etc/passwd –> userslist

adduser –> adduser, addgroup – add a user or group to the system

sudo passwd sample
to set a password for sample user.
sudo passwd -Sa
to check all the users having password or not.
set a password for the sample user

after setting the passwd for sample user

sudo passwd -d sample
d --> delete
NP --> no passwd

user-delete

sudo userdel sample
sudo userdel -r sample --> to delete with home

Group

to create group with user

to create a group

addgroup :

deletegroup :

sudo groupdel groupname
sudo delgroup groupname
sudo usermod -aG sudo username
permission to using i commands for new user
to give sudo or root previlage for new user.

MariaDb

By: Elavarasu
27 February 2024 at 11:22
sudo apt install mariadb-server mariadb-client

sudo systemctl status mariadb.servcie

to check the mariadb services.

sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service
sudo systemctl stop mariadb.service
sudo mysql_secure_installation

enter into the database using

mysql -u root -p

to view the default databases which present in mariadb using

show databases;
create new database using 
create database name;
show created database
show databases:
to use the exsisting database
use databasename;

MariaDb

By: Elavarasu
27 February 2024 at 11:22
sudo apt install mariadb-server mariadb-client

sudo systemctl status mariadb.servcie

to check the mariadb services.

sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service
sudo systemctl stop mariadb.service
sudo mysql_secure_installation

enter into the database using

mysql -u root -p

to view the default databases which present in mariadb using

show databases;
create new database using 
create database name;
show created database
show databases:
to use the exsisting database
use databasename;

Join

By: Elavarasu
25 February 2024 at 15:57
join file1 file2

join lines of two files on a common field. if no common fields are there then error should be occurs.

join -1 2 -2 1 s3.txt s4.txt

print unpairable lines using column number where FILE NUM is 1 or 2, corresponding to FILE1 or FILE2.


File

to determine the file type.

file filename
file -b filename
b --> brief
file *

it display all the file type including directory.


touch

It will create a empty file the it will change the time snap.

touch filename
touch file{1..20}.txt

It will create 20 empty files. file size are user defined we can create more files.

touch -d tomorrow filename

It will change the day

touch -r s1.txt s2.txt
r --> reference

time reference from s1.txt


Calendar

It display calendar


Reverse

Reverse the character


Redirection

> output Redirection | < input redirection

cat > filename
it will create a new file and we can give input to the file
cat < filename
it will display the file content
 wc < text.txt > text1.txt
cat < text1

it will save the wc of the file to file1
cat >> filename
adding the content to exisiting file
>> append

Tee

tee – read from standard input and write to standard output and files

df -Th | tee df.txt

Grep

grep – print lines that match patterns

grep "word" filename
grep "word" file1 file2
grep -i "word" file1 file2

Join

By: Elavarasu
25 February 2024 at 15:57
join file1 file2

join lines of two files on a common field. if no common fields are there then error should be occurs.

join -1 2 -2 1 s3.txt s4.txt

print unpairable lines using column number where FILE NUM is 1 or 2, corresponding to FILE1 or FILE2.


File

to determine the file type.

file filename
file -b filename
b --> brief
file *

it display all the file type including directory.


touch

It will create a empty file the it will change the time snap.

touch filename
touch file{1..20}.txt

It will create 20 empty files. file size are user defined we can create more files.

touch -d tomorrow filename

It will change the day

touch -r s1.txt s2.txt
r --> reference

time reference from s1.txt


Calendar

It display calendar


Reverse

Reverse the character


Redirection

> output Redirection | < input redirection

cat > filename
it will create a new file and we can give input to the file
cat < filename
it will display the file content
 wc < text.txt > text1.txt
cat < text1

it will save the wc of the file to file1
cat >> filename
adding the content to exisiting file
>> append

Tee

tee – read from standard input and write to standard output and files

df -Th | tee df.txt

Grep

grep – print lines that match patterns

grep "word" filename
grep "word" file1 file2
grep -i "word" file1 file2

Format | Head |Tail

By: Elavarasu
22 February 2024 at 14:49
fmt filename

collecting all the words and making it us a paragraph

fmt -u filename

Removing unwanted spaces and making it us a paragraph


Head

head filename
head filename1 filename2

it display first 10 values. because default value is 10

head -q filename filname2

it display first 10 values in each file and name cannot be displayed.


Tail

tail -n 3 filename

It display last 3 values

tail -f filename

it will display realtime values


Numbering

nl filename

It will display the content with numbers and only used for numbering purpose.

nl -s "/" filename

to add a string using -s .


Split

split filename

It will split the content then create new file and it will save the splitted content into the new file.

split -l2 tech.txt split1.txt

It will split the content with two lines then create the new file and saved it into the splitted content.


Tac

 tac filename

it will reverse the content


Last

last 

displays a list of all users logged in (and out) since that file was created.


Translate

tr

Translate, squeeze, and/or delete characters from standard input, writing to standard output.

tr [a-z] [A-Z] < tech.txt | head -n 3 > translated.txt

Sed

sed β€˜s/unix/linux/’ sample1.txt

sed  's/unix/linux/g'  sample1.txt

stream editor for filtering and transforming text.A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). g –> globally change the content without g it will change only first word. s -> search.


Paste

paste -d "||" state.txt tech.txt | head -n 3

Merge lines of files. Write lines consisting of the sequentially corresponding lines from each FILE, separated by TABs, to standard output.

d –> delimeter , β€œ|” it seperate the two merged files.

terminal

By: Elavarasu
22 February 2024 at 00:31
hostname -i

It displays host-id

hostname

It display hostname

$ --> it represent home
# --> it represent root
sudo su -

redirect to the root user

cd ~

to change history size using shell

which $SHELL

to know which shell is used.

vim ~/.bashrc
edit the history size and modify it.
press tab to auto fill the command
ls -a

to display the hidden files

ls -lah

to display hidden files with human readable

Format | Head |Tail

By: Elavarasu
22 February 2024 at 14:49
fmt filename

collecting all the words and making it us a paragraph

fmt -u filename

Removing unwanted spaces and making it us a paragraph


Head

head filename
head filename1 filename2

it display first 10 values. because default value is 10

head -q filename filname2

it display first 10 values in each file and name cannot be displayed.


Tail

tail -n 3 filename

It display last 3 values

tail -f filename

it will display realtime values


Numbering

nl filename

It will display the content with numbers and only used for numbering purpose.

nl -s "/" filename

to add a string using -s .


Split

split filename

It will split the content then create new file and it will save the splitted content into the new file.

split -l2 tech.txt split1.txt

It will split the content with two lines then create the new file and saved it into the splitted content.


Tac

 tac filename

it will reverse the content


Last

last 

displays a list of all users logged in (and out) since that file was created.


Translate

tr

Translate, squeeze, and/or delete characters from standard input, writing to standard output.

tr [a-z] [A-Z] < tech.txt | head -n 3 > translated.txt

Sed

sed β€˜s/unix/linux/’ sample1.txt

sed  's/unix/linux/g'  sample1.txt

stream editor for filtering and transforming text.A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). g –> globally change the content without g it will change only first word. s -> search.


Paste

paste -d "||" state.txt tech.txt | head -n 3

Merge lines of files. Write lines consisting of the sequentially corresponding lines from each FILE, separated by TABs, to standard output.

d –> delimeter , β€œ|” it seperate the two merged files.

terminal

By: Elavarasu
22 February 2024 at 00:31
hostname -i

It displays host-id

hostname

It display hostname

$ --> it represent home
# --> it represent root
sudo su -

redirect to the root user

cd ~

to change history size using shell

which $SHELL

to know which shell is used.

vim ~/.bashrc
edit the history size and modify it.
press tab to auto fill the command
ls -a

to display the hidden files

ls -lah

to display hidden files with human readable

History commands

By: Elavarasu
9 February 2024 at 13:04
history

to display the last 1000 commands we executed in our machine. we can increase the limit and the default size is 1000.

history 10

execute last 10 commands

history | head

it display first 10 commands

history | tail

it displays last 10 commands

history ! 950

execute the specific command using event number like 950

history -d 950

delete the command using also event number

history -c

delete all the 1000 commands permanently

❌
❌