Table of Contents

Middleware

Docker CLI Commands Cheet Sheat



Web Sites

2013            2017

                docker 17.03

Docker  --+---  Docerk CE (Community Edition)
          |
          +---  Docker  EE (Enterprise Edition)


Installing Docker

CentOS7.X/RHEL7.X

# yum install docker
# docker --version
Docker version 1.12.6, build 85d7426/1.12.6

or

# yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

# yum install -y yum-utils device-mapper-persistent-data lvm2
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# yum install -y docker-ce docker-ce-cli containerd.io
# docker --version
Docker version 19.03.8, build afacb8b
# systemctl start docker
# systemctl status docker
# systemctl enable docker
# systemctl enable docker.service
# systemctl start docker.service
# docker -v
# docker info


Docker Commands

Docker image Operation

Commands Note Example
docker search docker search centos
docker images List of locally downloaded images with docker pull docker images
docker pull Pull an image or a repository from a Docker Registry docker pull centos:latest
docker pull centos:centos7
docker pull centos:centos5
docker rmi Remove one or more images docker rmi centos

Docker Container Operation

Commands Note Example
docker run Run a command in a new container
If there is a specified image locally, start from there, otherwise, download from the above Docker Hub and start
-it : Start the container in an operable state
see below
docker inspect Return low-level information on Docker objects docker inspect xxxxxx
docker rm Remove one or more containers docker rm CONTAINERID
docker ps List containers docker ps
docker ps -a ← List including finished containers
docker start Start a container docker start CONTAINERNAME
docker stop Stop a container docker stop CONTAINERNAME
docker attach Attach to a running container
Get inside the container
Dettach is Ctrl + P Ctrl + Q
docker attach CONTAINERNAME
docker exec docker exec CONTAINERID ps -aux
docker exec -it CONTAINERID /bin/bash
docker commit Create a new image from a container's changes docker commit CONTAINER-ID centos:centos7


Docker Operation Example

# docker pull  centos:7        <- About 70MB
# docker images
# docker run -it --name centos7_test1 centos /bin/bash

# Ctrl+d   <- For exit and finish docker
or
# Ctrl+p + Ctrl+q   <- For exit but not finish dokcer

# docker ps -a


docker run examples

OS Example

# docker run -it --name centos7-1 centos:7
# docker run -d -it --name centos7-1 centos:7
# docker run -d -it --name centos7-1 -h cetntos7-1 centos:7
# docker run -d -it --name centos7-5 -e TZ=Aaia/Tokyo centos:7
# docker exec cont1 env | grep TZ
# cat ./envfile
TZ=Asia/Tokyo
LANG=ja_JP.utf8
# docker run -d -it --name cont1 --env-file ./envfile centos:7


Web Example

# docker run -d --name httpd1 -p 8080:80 httpd
# curl http://localhost:8080/
# mkdir -p /var/docker/cont1/htdocs
# echo 'test' > /var/docker/htdocs/index.html
# docker run -d -p 8080:80 -v /var/docker/htdocs:/usr/local/apache2/htdocs --name httpd1 httpd
# curl http://localhost:8080/

run the container in the background

# docker run --privileged -d -p 80:80 --name httpd fnya/apache /sbin/init
    -d : Detached mode: run the container in the background and print the new container ID.

# docker exec -it httpd /bin/bash

[root@centos7 ~]# systemctl enable httpd.service
[root@centos7 ~]# systemctl start httpd.service
[root@centos7 ~]# exit

# curl -s http://localhost/ | head -n 1
# docker images
# docker stop  XXXXXX


Network

Work with network commands

Check Docker Network

# brctl show           <- yum install  bridge-utils

# docker network ls

# ifconfig
# ifconfig docker0

# docker network inspect bridge


Create Bridge Network

# docker network create --driver bridge --subnet=192.168.0.0/24 --gateway=192.168.0.1 --opt "com.docker.network.bridge.name"="docker1" my-network
# docker network inspect my-network    <- check my-network
# docker run --name container1 --net my-network --ip 192.168.33.11 -dt centos


How to use static IP address.

# docker network create --subnet=192.168.10.0/24 test_nw
# docker network ls
# docker network inspect test_nw

# docker run -it --name test --net=test_nw --ip=192.168.10.100 -d centos:centos6 /bin/bash


Storage

How to use Host OS's Volume

# docker run -i -t -v /var/volume:/root centos /bin/bash

/var/vlume is host OS's volume.
/root is container's volume.


Data Volume Container

How to create Data Volume Container
# docker run -d --name data -v /root centos /bin/bash




Training using Docker

draw.io

# docker pull fjudith/draw.io
# docker run -it --rm --name="draw" -p 8080:8080 -p 8443:8443 fjudith/draw.io
# docker ps -a | grep draw

http://x.x.x.x:8080/


zabbix

docker run --name zabbix-appliance -t \
      -p 10051:10051 \
      -p 80:80 \
      --restart unless-stopped \
      -d zabbix/zabbix-appliance:latest

http://x.x.x/
user:Admin pass:zabbix


jenkins

# docker pull jenkins/jenkins:lts
# docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
TIPS

Since the data that needs to be persisted is created in /var/jenkins_home in the container, mount it on the localhost side in the current directory jenkins_home.

docker run -d -v `pwd`/jenkins_home:/var/jenkins_home -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts


gitbucket

# docker pull gitbucket/gitbucket
# docker run -d -p 8080:8080 gitbucket/gitbucket

user:root password:root

TIPS
# docker run -d -p 8080:8080 -p 29418:29418 -v `pwd`/gitbucket:/gitbucket gitbucket/gitbucket

-p 29418:29418    for ssh
-v `pwd`/gitbucket:/gitbucket   for specify the location of the data directory