Miscellaneous Table of Content




Subscribe To Our Newsletter
You will receive our latest post and tutorial.
Thank you for subscribing!

required
required


Visual Studio Code Hot Keys

Search

Search for file in your space

Windows

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
CTRL + P
CTRL + P
CTRL + P

Mac

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
command + P
command + P
command + P

 

May 26, 2020

Docker Guide

What is docker?

Getting Started

Download docker and install it on your computer

  • Link to developer guide – https://docs.docker.com/ee/
  • Select the docker option based on your operation system. In my case, I selected Docker for desktop mac. Then from there should be a link to download the docker executable onto your computer.
  • You will have to create a docker account to download docker.
  • Install docker by double-clicking on the executable your downloaded and follow instructions.

Docker commands

You are going to use the command-line interface to work with Docker.

docker images
– list out all the images in your computer

docker ps -a
– list out all the running containers on your computer

docker rmi imageId
– delete or remove an image.

docker stop containerId
– stop a running container

docker rm containerId
– delete a container

docker pull image: tag
– pull an image from a docker registry(docker hub or AWS ECR).

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker pull mysql
docker pull mysql
docker pull mysql

 

Run docker container automatically

Use these tags 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
-dit --restart unless-stopped
-dit --restart unless-stopped
-dit --restart unless-stopped

docker run -p outside-port:internal-port –name container-name -dit –restart unless-stopped -d image_name:image_tag
– run docker container with the port where the container will use both externally and internally, the name of the container, the image, and tag being used, and a command to make sure the container will restart if it stops.

– -d means that to run container in background and print container ID

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker run -p outside-port:internal-port --name container-name -dit --restart unless-stopped -d image_name:image_tag
docker run -p outside-port:internal-port --name container-name -dit --restart unless-stopped -d image_name:image_tag
docker run -p outside-port:internal-port --name container-name -dit --restart unless-stopped -d image_name:image_tag
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker run -p 8080:8080 --name springboot-hello-0-0-1 -dit --restart unless-stopped -d springboot-hello:0-0-1
docker run -p 8080:8080 --name springboot-hello-0-0-1 -dit --restart unless-stopped -d springboot-hello:0-0-1
docker run -p 8080:8080 --name springboot-hello-0-0-1 -dit --restart unless-stopped -d springboot-hello:0-0-1

 

Push up a docker image to aws docker registry

1. Login to aws ECR from your computer

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
aws ecr get-login-password --profile folauk110
aws ecr get-login-password --profile folauk110
aws ecr get-login-password --profile folauk110

2. Build image

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker build -t project .
docker build -t project .
docker build -t project .

3. Tag image

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker tag project:latest remote-ecr-url/project:latest
docker tag project:latest remote-ecr-url/project:latest
docker tag project:latest remote-ecr-url/project:latest

4. Push image to remote registry

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker push remote-ecr-url/project:latest
docker push remote-ecr-url/project:latest
docker push remote-ecr-url/project:latest

 

SSH into a docker container

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker exec -it {container-name} sh
docker exec -it {container-name} sh
docker exec -it {container-name} sh

or

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker exec -it {container-name} sh /bin/bash
docker exec -it {container-name} sh /bin/bash
docker exec -it {container-name} sh /bin/bash

 

Install Redis using docker

Pull redis docker image

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker pull redis
docker pull redis
docker pull redis

Run redis docker container

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker run --name container-redis -dit --restart unless-stopped -p 6379:6379 -d redis
docker run --name container-redis -dit --restart unless-stopped -p 6379:6379 -d redis
docker run --name container-redis -dit --restart unless-stopped -p 6379:6379 -d redis

Set keys and values in redis

First, ssh into the redis container.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker exec -it container-redis sh
docker exec -it container-redis sh
docker exec -it container-redis sh

Second, use the redis-cli

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
redis-cli
redis-cli
redis-cli
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
127.0.0.1:6379> set docker great
OK
127.0.0.1:6379> get docker
"great"
127.0.0.1:6379> set name objectrocket
OK
127.0.0.1:6379> get name
"objectrocket"
127.0.0.1:6379> set docker great OK 127.0.0.1:6379> get docker "great" 127.0.0.1:6379> set name objectrocket OK 127.0.0.1:6379> get name "objectrocket"
127.0.0.1:6379> set docker great
OK
127.0.0.1:6379> get docker
"great"
127.0.0.1:6379> set name objectrocket
OK
127.0.0.1:6379> get name
"objectrocket"

 

Install Elasticsearch using docker

Pull elasticsearch docker image

Make sure to use the right version that your code and Kibana is using.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.1.0
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.1.0
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.1.0

Run elasticsearch docker container

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch -e "discovery.type=single-node" -dit --restart unless-stopped -d docker.elastic.co/elasticsearch/elasticsearch:7.1.0
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch -e "discovery.type=single-node" -dit --restart unless-stopped -d docker.elastic.co/elasticsearch/elasticsearch:7.1.0
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch -e "discovery.type=single-node" -dit --restart unless-stopped -d docker.elastic.co/elasticsearch/elasticsearch:7.1.0
Add Elasticsearch Password
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
-e ELASTIC_PASSWORD=MagicWord
-e ELASTIC_PASSWORD=MagicWord
-e ELASTIC_PASSWORD=MagicWord
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch -e "discovery.type=single-node" -e ELASTIC_PASSWORD=DDloadjes233j -dit --restart unless-stopped -d docker.elastic.co/elasticsearch/elasticsearch:7.1.0
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch -e "discovery.type=single-node" -e ELASTIC_PASSWORD=DDloadjes233j -dit --restart unless-stopped -d docker.elastic.co/elasticsearch/elasticsearch:7.1.0
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch -e "discovery.type=single-node" -e ELASTIC_PASSWORD=DDloadjes233j -dit --restart unless-stopped -d docker.elastic.co/elasticsearch/elasticsearch:7.1.0

 

Install Kibana using docker

Pull kibana docker image

Make sure to use the right version that your code and elasticsearch is using.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker pull docker.elastic.co/kibana/kibana:7.1.0
docker pull docker.elastic.co/kibana/kibana:7.1.0
docker pull docker.elastic.co/kibana/kibana:7.1.0

Run kibana docker container 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker run --link elasticsearch:elasticsearch -dit --restart unless-stopped --name kibana -p 5601:5601 docker.elastic.co/kibana/kibana:7.1.0
docker run --link elasticsearch:elasticsearch -dit --restart unless-stopped --name kibana -p 5601:5601 docker.elastic.co/kibana/kibana:7.1.0
docker run --link elasticsearch:elasticsearch -dit --restart unless-stopped --name kibana -p 5601:5601 docker.elastic.co/kibana/kibana:7.1.0

Access kibana locally by going on http://localhost:5601/app/kibana

Add Elasticsearch Password

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# add elasticsearch password
-e ELASTICSEARCH_PASSWORD=DDloadjes233j
Example
docker run --link elasticsearch:elasticsearch -e ELASTICSEARCH_PASSWORD=DDloadjes233j -dit --restart unless-stopped --name kibana -p 5601:5601 docker.elastic.co/kibana/kibana:7.1.0
# add elasticsearch password -e ELASTICSEARCH_PASSWORD=DDloadjes233j Example docker run --link elasticsearch:elasticsearch -e ELASTICSEARCH_PASSWORD=DDloadjes233j -dit --restart unless-stopped --name kibana -p 5601:5601 docker.elastic.co/kibana/kibana:7.1.0
# add elasticsearch password
-e ELASTICSEARCH_PASSWORD=DDloadjes233j

Example
docker run --link elasticsearch:elasticsearch -e ELASTICSEARCH_PASSWORD=DDloadjes233j -dit --restart unless-stopped --name kibana -p 5601:5601 docker.elastic.co/kibana/kibana:7.1.0

Logstash

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# pull image
docker pull docker.elastic.co/logstash/logstash:7.15.0
# run container
docker run -dit --restart unless-stopped --name logstash -v ~/pipeline/:/usr/share/logstash/pipeline/ docker.elastic.co/logstash/logstash:7.15.0
# pull image docker pull docker.elastic.co/logstash/logstash:7.15.0 # run container docker run -dit --restart unless-stopped --name logstash -v ~/pipeline/:/usr/share/logstash/pipeline/ docker.elastic.co/logstash/logstash:7.15.0
# pull image
docker pull docker.elastic.co/logstash/logstash:7.15.0

# run container
docker run -dit --restart unless-stopped --name logstash -v ~/pipeline/:/usr/share/logstash/pipeline/ docker.elastic.co/logstash/logstash:7.15.0

 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker pull docker.elastic.co/logstash/logstash:7.15.0
docker pull docker.elastic.co/logstash/logstash:7.15.0
docker pull docker.elastic.co/logstash/logstash:7.15.0

 

Postgresql with docker

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#pull image
docker pull postgres:12.6
#run docker container
docker run --name postgres --restart unless-stopped -p 5432:5432 -e POSTGRES_PASSWORD=test -v /Users/folaukaveinga/Software/postgres/data:/var/lib/postgresql/data -d postgres:12.6
#pull image docker pull postgres:12.6 #run docker container docker run --name postgres --restart unless-stopped -p 5432:5432 -e POSTGRES_PASSWORD=test -v /Users/folaukaveinga/Software/postgres/data:/var/lib/postgresql/data -d postgres:12.6
#pull image
docker pull postgres:12.6
#run docker container
docker run --name postgres --restart unless-stopped -p 5432:5432 -e POSTGRES_PASSWORD=test -v /Users/folaukaveinga/Software/postgres/data:/var/lib/postgresql/data -d postgres:12.6

 

Ubuntu with docker

Sometimes when you want to play or learn linux you want to have a linux OS to play with. With docker you can pull a ubuntu docker image and run it locally.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker pull ubuntu
docker pull ubuntu
docker pull ubuntu

Run a ubuntu container

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker run -it ubuntu /bin/bash
docker run -it ubuntu /bin/bash
docker run -it ubuntu /bin/bash

You will be in the root folder of the ubuntu container right away after running the above command.

Restart a docker container

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker container restart [OPTIONS] CONTAINER [CONTAINER...]
// -t or --time represents seconds to wait for stop before killing the container
docker container restart -t 5 bee0a80b1424
docker container restart [OPTIONS] CONTAINER [CONTAINER...] // -t or --time represents seconds to wait for stop before killing the container docker container restart -t 5 bee0a80b1424
docker container restart [OPTIONS] CONTAINER [CONTAINER...]

// -t or --time represents seconds to wait for stop before killing the container
docker container restart -t 5 bee0a80b1424

 

View logs of a docker container

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker logs [OPTIONS] CONTAINER
// Follow log output -f or --follow
docker logs -f asdfwers
docker logs [OPTIONS] CONTAINER // Follow log output -f or --follow docker logs -f asdfwers
docker logs [OPTIONS] CONTAINER

// Follow log output -f or --follow
docker logs -f asdfwers

 

 

August 20, 2019

Terminate process(PID) command

 

If you ever run multiple java projects (microservices) on eclipse. Most of the time you want to start them up all at the same time and luckily eclipse has this feature. Unfortunately what Eclipse doesn’t have is a way to stop or kill all of you java projects(processes) all at the same time. This is useful when you want fresh and clean instances for all my microservices and not have any process in a stale state.

To terminate all of your projects or java processes, do this:

  • Open up terminal and type in this command “killall java”
  • Or open terminal within your eclipse. Open Eclipse, right-click on a project in the Package Explorer panel, hover over Show in, select terminal, and type in this command “killall java”

 

August 20, 2019

Intellij Hot Keys

Reformat Code

For Mac

⌥ ⌘ L

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
command + option + l
command + option + l
command + option + l

View Structure/Outline of Class

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
command + 7
command + 7
command + 7

 

 

 

June 7, 2018