Skip to main content

Posts

Showing posts from February, 2019

Nginx - Host a static website

Greetings!

Let's play with nginx and serve a static website. ;)
Step 1: Install nginx sudo apt install nginx
Step 2: Update hosts file to add our site name sudo vim /etc/hosts 127.0.0.1 nginx-site.com
Step 3: Unlink default site cd /etc/nginx/sites-enabled sudo unlink default
Step 4: Create folder for the site cd /var/www sudo mkdir nginx-site.com sudo chmod o+w nginx-site.com touch nginx-site.com/index.html echo "coming soon" > nginx-site.com/index.html
Step 5: Configure nginx Now we need to nginx where to find our site.

sites-available - contains configurations for available sitessites-enabled - contains links to configurations in sites-available. Nginx uses this location to read and run.
sudo vim /etc/nginx/sites-available/nginx-site.com server { listen 80 default_server; listen [::]:80 default_server; root /var/www/nginx-site.com; index index.html; server_name nginx-site.com www.nginx-site.com; location / { …

Docker - Containerizing Spring Boot Application

Greetings!

It is easy to containerize our spring boot application using docker. Let's begin.

Source code

Step 1:
Create a simple Spring boot application.
mvn clean package
Step 2:
Create Dockerfile
FROM openjdk:8-jdk-alpine VOLUME /tmp COPY target/spring-docker-0.0.1-SNAPSHOT.jar spring-docker-0.0.1-SNAPSHOT.jar ENTRYPOINT ["java","-jar","/spring-docker-0.0.1-SNAPSHOT.jar"]
Step 3:
Create a docker image using our Dockerfile
docker build -t spring-docker-1 .
Step 4:
Make sure our image is built.
docker images
Step 5:
Create a container using our Spring boot image.
docker container run -d -p 8080:8080 --name sd-1 spring-docker-1
Step 6:
Check logs to see whether it is started correctly.
docker logs sd-1
Step 7:
Go to web browser to see our app in action.
http://localhost:8080/
http://localhost:8080/echo

Awesome work! Now we have a running Docker container of our Spring boot application.

Docker - Mysql as a Container

Greetings!

How do you(we) run Mysql database in our development, QA or production environment? Install required packages, configure, open ports, monitor as necessary. So many things to do and it is repeating over all the environments. Why repeat when we have Docker!

First make sure you have installed Docker.
docker -v
Get the MySQL image Let's pull the Mysql image from the docker hub.
Official MySQL docker image
docker pull mysql
Make sure it is downloaded.
docker images
Creating the MySQL container Let's create a container from it and go inside.
docker container run -d -p 3306:3306 --name mysql-test -e MYSQL_ROOT_PASSWORD=secret mysql docker exec -it mysql-test bash
Now we are inside our mysql docker container. We can use all our mysql commands from here.
# mysql -uroot -p # Enter password:secret # create database docker-test
Type exit to exit from the container.

Inspecting the container Check and inspect our container to get more details.
docker container mysql-test ls docker conta…