Monday, July 23, 2018

Push docker container

In this post, I will give you an example for what I do to push a docker container into docker hub.

Here I will use my repository in docker hub i.e. arwankhoiruddin/hadoopbuild. You can find it here: https://hub.docker.com/r/arwankhoiruddin/hadoopbuild/

In order to modify it, first I have to login

$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username (arwankhoiruddin): arwankhoiruddin
Password: 
Login Succeeded

Then I run the docker image

$ docker run -it arwankhoiruddin/hadoopbuild /bin/bash

If it is not in my computer, it will download automatically from docker hub. After I finish, I type exit and I can save the changes into the docker hub. Followings are the steps

$ docker ps -a
CONTAINER ID        IMAGE                   COMMAND             CREATED             STATUS                         PORTS               NAMES
856e27749098        ubuntu:14.04            "/bin/bash"         About an hour ago   Exited (0) About an hour ago                       awesome_aryabhata

Then commit the changes

$ docker commit 856e27749098 arwankhoiruddin/hadoopbuild

Tag the image

$ docker tag arwankhoiruddin/hadoopbuild latest

Push the image

$ docker push arwankhoiruddin/hadoopbuild
The push refers to repository [docker.io/arwankhoiruddin/hadoopbuild]
eed11865a805: Pushing [=>                                                 ]  19.82MB/959.3MB
776d5289b76e: Layer already exists 
0fb55a72eab2: Layer already exists 
a30ab2bcda94: Layer already exists 
99840408c5ea: Layer already exists 
a8e78858b03b: Layer already exists 

Done

Wednesday, July 18, 2018

Getting Started with Flask

In this post, I will give you a very basic example to run a hello world program in flask. What make it different with the other tutorial is that this will enable your program to run from a cloud server, not just on a local server.

Before we go further

Because you want to run it in a cloud server, most probably you will use your ssh to connect and run it. However, you need to know that when you end your ssh session, your Flask server will also be shut down. To prevent that, my favourite is to use screen. If you are ubuntu lover like me, you can install it by typing

$ sudo apt-get install -y screen

Before you do any work, start by typing

$ screen

It will open a session for you. Later, after you run your Flask server, you may want to detach the session using this command

ctrl-a d

If you later want to go back to your session, you can do it by using the following command

$ screen -r

OK, without further ado, this is your first hello world program in Flask

# hello.py

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
    return 'hello world'

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

You can run the program using

$ python hello.py

Say that you run it in cloud with address 183.93.3.23, you can open the hello world program from your browser by typing

183.93.3.23:5000

This will show you a welcome message

hello world

After I mentioned earlier, if you want to let your hello world server to run, you can just detach from the session using the following command in terminal

ctrl-a d

Hope it helps :D

Tuesday, May 15, 2018

Some useful SSH Commands

Install SSH Server in Ubuntu

sudo apt-get install openssh-server

Run SSH Server

sudo service ssh restart

The output will be like

* Restarting OpenBSD Secure Shell server sshd [ OK ]

Check SSH Status

ps -ef |grep "sshd"

The output will be like

hduser@d1:/hadoopSetup$ ps -ef | grep "sshd"
root       125     0  0 02:35 ?        00:00:00 /usr/sbin/sshd
hduser     138    79  0 02:45 pts/2    00:00:00 grep --color=auto sshd