The Docker Ninja

Posted on Sun 23 February 2020 in Technology

Docker Resource Kit

Installing Docker

Ubuntu

curl -sSL https://get.docker.com/ | sudo sh

MacOS

brew install docker

Docker Compose

Find below the link with instructions:
Docker Compose Install

Important tip: Always check if you have your Docker Repo updated:
- /etc/yum.repos.d/docker.repo (RHEL)
- /etc/apt/sources.list.d (Ubuntu/Debian)

Containers - Downloading Images and Creating Containers

docker run -dit ubuntu:latest

Containers Operational Cycle

docker ps -a  # List all containers created
docker start $(docker ps -a -q)
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

Containers by Status

docker start $(docker ps -aq -f status=exited)
docker rm $(docker ps -aq -f status=exited)
sudo docker ps -a | grep exited | cut -d ' ' -f 1 | xargs sudo docker rm

Removing Docker Images

docker rmi $(sudo docker images | grep 'image_name' | tr -s ' ' | cut -d ' ' -f 3)
docker rmi $(docker images | grep 'gcr' | tr -s ' ' | cut -d ' ' -f 3)
docker rmi $(docker images | grep 'docker' | tr -s ' ' | cut -d ' ' -f 3)
docker image prune

Saving Images

  1. Create a container from any pulled image:
    bash docker run -it 'base_image' /bin/bash
  2. Make necessary changes (e.g., install updates/software).
  3. Commit it with a new image name:
    bash docker commit 'container_id' new_image

Installing Products with Docker

Jenkins

docker run -p 8080:8080 -v jenkins-data:/var/jenkins_home -v $(which docker):/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -v "$HOME":/home jenkinsci/blueocean

WordPress Stack

MariaDB (SQL Database):

docker run -e MYSQL_ROOT_PASSWORD=mariadb -e MYSQL_DATABASE=wordpress --name wordpressdb -v "$PWD/database":/var/lib/mysql -d mariadb:latest

WordPress:

docker run -e WORDPRESS_DB_PASSWORD=mariadb --name wordpress --link wordpressdb:mysql -p 0.0.0.0:80:80 -v "$PWD/html":/var/www/html -d wordpress

Splunk

docker run --name splunkwls --hostname splunk01 -p 8000:8000 -e "SPLUNK_START_ARGS=--accept-license" -v "$PWD/opt":/opt/splunk/var splunk/splunk:latest

HTTPD - Apache

docker run -dit --name my-apache-app -v "$PWD":/usr/local/apache2/htdocs/ -p 8000 httpd:2.4

Rancher

docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:stable

Ubuntu

docker pull ubuntu:latest
docker run -it -p 8080:80 -p 4443:443 --name 'containername' ubuntu:latest /bin/bash

Jira

docker run -d -p 8080:8080 -v jiravolume:/var/atlassian/jira --name bernardojira blacklabelops/jira

WebLogic

docker run -d --name b-001wls -p 7001:7001 -e ADMIN_USERNAME=weblogic -e ADMIN_PASSWORD=welcome1 -e DOMAIN_HOME=/u01/oracle/user_projects/domains/b001_domain -e DOMAIN_NAME=b001_domain oracle/weblogic:12.2.1.3-generic

Docker Machine

docker-machine create -d virtualbox rancher01

SysDig

docker run -d --name sysdig-agent --privileged --net host --pid host -e ACCESS_KEY=YOUR_ACCESS_KEY -v /var/run/docker.sock:/host/var/run/docker.sock -v /dev:/host/dev -v /proc:/host/proc:ro -v /boot:/host/boot:ro -v /lib/modules:/host/lib/modules:ro -v /usr:/host/usr:ro sysdig/agent

Docker Cleanup

docker system prune --all -f
docker image prune --all -f

Cheers...

Docker Resource Kit

Installing Docker

Ubuntu 
    curl -sSL https://get.docker.com/ | sudo sh

MacOS 
    brew install docker

Docker Compose

Find below the link with instructions:

Docker Compose Install

Important tip, always check if you have your Docker Repo updated

/etc/yum.repos.d/docker.repo    (RHEL)
/etc/apt/sources.list.d (ubuntu / Debian Likes)

Containers - Downloading Images and Creating containers

docker run -dit ubuntu:latest

Containers operational cycle

docker ps -a (List all containers created)
docker start $(docker ps -a -q)
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

Containers = per Status

docker start $(docker ps -aq -f status=exited)
docker rm $(docker ps -aq -f status=exited)
sudo docker ps -a | grep exited | cut -d ' ' -f 1 | xargs sudo docker rm

Docker removing Images - Docker rmi

Usage:

docker rmi $( sudo docker images | grep ‘'image_name'' | tr -s ' ' | cut -d ' ' -f 3)

Images = grep string gcr = google

docker rmi $( docker images | grep 'gcr' | tr -s ' ' | cut -d ' ' -f 3)
docker prune image

Images = grep string doc = docker

docker rmi $( docker images | grep ‘docker' | tr -s ' ' | cut -d ' ' -f 3)

Saving Images

COMMIT savings into an image

First, create a container from any pulled image!

docker run -it 'base_image' /bin/bash

Make the necessary changes (Install updates and softwares you wish)

Example: 
yum -y upgrade && yum -y update
yum install httpd (RHEL)
RUN apt-get update && apt-get install -y props (Ubuntu)
RUN apt-get update && apt-get install -y iputils-ping (Ubuntu)

Commit it with a new name Image.

docker commit 'hash tag of running container' new_image

Installing Products (images) with Docker

Jenkins

Running the container 

docker run -p 8080:8080 -v jenkins-data:/var/jenkins_home -v $(which docker):/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -v "$HOME":/home jenkinsci/blueocean
Removing container after execution

docker run --rm -u root -p 8080:8080 -v jenkins-data:/var/jenkins_home -v $(which docker):/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -v "$HOME":/home jenkinsci/blueocean

This is handy because in Jenkins is usual you find the message : "Docker not found", using this approach, it has been solved!

Cleanup Images

docker system prune --all 
docker image prune --all

Forcing without confirmation
docker system prune --all -f
docker image prune --all -f

WordPress Stack

mariaDB (SQL Database)

docker run -e MYSQL_ROOT_PASSWORD=mariadb -e MYSQL_DATABASE=wordpress --name wordpressdb -v $PWD/database":/var/lib/mysql -d mariadb:latest

Wordpress

docker run -e WORDPRESS_DB_PASSWORD=mariadb --name wordpress --link wordpressdb:mysql -p 0.0.0.0:80:80 -v "$PWD/html":/var/www/html -d wordpress

variables
MYSQL_ROOT_PASSWORD='db_password'
MYSQL_DATABASE='name_database'

Splunk

Example1:
docker run --name splunkwls --hostname splunk01 -p 8000:8000 -e "SPLUNK_START_ARGS=--accept-license" -v "$PWD/opt":/opt/splunk/var splunk/splunk:latest

Example2:
docker run -d --name splunkwls --hostname splunk01 -p 8000:8000 -e "SPLUNK_START_ARGS=--accept-license" -v /opt/oracle/Middleware/domains/snake01/servers:/mnt/splunk splunk/splunk

user=passwd: admin/admin01

Example:
Vars = /host/directory:/container/directory

HTTPD - APACHE

DOCKER HTTPD IMAGE - as reference (only)

docker pull http

docker run -dit --name my-apache-app -v "$PWD":/usr/local/apache2/htdocs/ -p 8000 httpd:2.4

docker run -dit —name my-apache-app -v "$PWD":/usr/local/apache2/htdocs/ -p 192.168.1.4:80:9000 httpd:2.4

RANCHER --> Amazing Product!

docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:stable

docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:preview

UBUNTU

docker pull ubuntu:latest

docker run -it -p 8080:80 -p 4443:443 —name 'containername' 'containerimage' ubuntu:latest /bin/bash

Jira - Docker

https://hub.docker.com/r/blacklabelops/jira/

docker run -d -p 8080:8080 -v jiravolume:/var/atlassian/jira --name bernardojira blacklabelops/jira

DOCKER WEBLOGIC 12.2.1.3

Copy and paste below:

docker run -d  —name b-001wls -p 7001:7001 -e ADMIN_USERNAME=weblogic -e ADMIN_PASSWORD=welcome1 -e DOMAIN_HOME=/u01/oracle/user_projects/domains/b001_domain -e DOMAIN_NAME=b001_domain oracle/weblogic:12.2.1.3-generic

DOCKER & RED HAT

Installing DOCKER CE (Community Edition on Red HAT Enterprise)

Container SELINUX

yum install -y http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.33-1.git86f33cd.el7.noarch.rpm

Package Name: container-selinux-2.33-1.git86f33cd.el7.noarch.rpm

DOCKER MACHINE Driver: VirtualBox (Oracle)

docker-machine create -d virtualbox rancher01

docker-machine create -d 'drive : virtualbox, vmware, cloud 'virtual machine name'

SysDig

docker run -d --name sysdig-agent --privileged --net host --pid host -e ACCESS_KEY=YOUR_ACCESS_KEY -v /var/run/docker.sock:/host/var/run/docker.sock -v /dev:/host/dev -v /proc:/host/proc:ro -v /boot:/host/boot:ro -v /lib/modules:/host/lib/modules:ro -v /usr:/host/usr:ro sysdig/agent

Docker inspect feature

docker inspect 'CONTAINER ID' | grep -w "IPAddress" | awk '{ print $2 }' | head -n 1 | cut -d "," -f1

Go ahead and take a look yourself at DockerFiles, Docker Swarm, Docker Compose

Cheers...