Saturday, August 12, 2017

Docker Tutorial

Install docker on Ubuntu

Installation guild is in:

To install Docker CE, you need the 64-bit version of one of these Ubuntu versions:
  • Zesty 17.04
  •  Xenial 16.04 (LTS)
  •  Trusty 14.04 (LTS)

check OS version:
vagrant@exp:/devops/PPM/942$ cat /etc/*-release
wget  --verbose -P /tmp


If run into this issue:
dpkg: dependency problems prevent configuration of docker-ce:
 docker-ce depends on libltdl7 (>= 2.4.6); however:
  Package libltdl7 is not installed.

sudo apt-get update
sudo apt-get install libltdl7

Setup proxy

When you download a docker image, and run into issue docker:
Error response from daemon: Get net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).

This is because you are running docker behind a proxy, and need to setup proxy for docker


sudo mkdir -p /etc/systemd/system/docker.service.d
      sudo vim /etc/systemd/system/docker.service.d/http-proxy.conf

Environment="HTTP_PROXY=YOUR_PROXY" "HTTPS_PROXY=YOUR_PROXY" "http_proxy=YOUR_PORXY" "https_proxy=YOUR_PROXY" "no_proxy=localhost,," "NO_PROXY=localhost,,"

Flush changes
sudo systemctl daemon-reload
Check changes are effective
systemctl show --property=Environment docker
Restart docker service
sudo systemctl restart docker

Run Tomcat

Choose an image:

docker run command:

Run tomcat:
sudo docker run -it --name mytomcat1 -p 8080:8080 tomcat:8.0

This may take a long time to download the image.

Check container status:
sudo docker ps -a
(-a check all containers, without it, will only check running containers)

Check image:
sudo docker image ls

Start/stop container:
sudo docker start mytomcat1
sudo docker stop mytomcat1
sudo docker restart mytomcat1

Check container logs:
sudo docker logs -f mytomcat1

Find out the process running inside docker:
ubuntu@exp1:~$ sudo docker top mytomcat1
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                5566                5549                0                   07:34               ?                   00:00:04            /docker-java-home/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/ -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat org.apache.catalina.startup.Bootstrap start

Go inside the container:  
sudo docker exec -it mytomcat1 /bin/sh
(working directory from Dockerfile)

Find out the processing running inside docker:
# ps -fwww 1
root         1     0  1 07:40 ?        Ssl    0:03 /docker-java-home/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/ -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat org.apache.catalina.startup.Bootstrap start

#cd logs

Restart and go inside mytomcat1, logs/ is still there

Remove container:
sudo docker rm mytomcat1

Recreate container:
sudo docker run -it --name mytomcat1 -p 8080:8080 tomcat:8.0

Access tomcat

Run another tomcat container with volume:

sudo docker run -d --name mytomcat2 -p 8081:8080 -v /devops/mytomcat/logs:/usr/local/tomcat/logs tomcat:8.0

Check host folder /devops/mytomcat/logs, see it has tomcat logs

Share volumes among dockers:
sudo docker run -d --name mytomcat2 -p 8081:8080 -v /devops/mytomcat/logs:/usr/local/tomcat/logs tomcat:8.0

sudo docker run -d --name mytomcat3 -p 8082:8080 --volumes-from mytomcat2 tomcat:8.0

Debug Docker Daemon

Change debug to true:
sudo vim /etc/docker/daemon.json

  "debug": true,

Restart docker:
sudo systemctl restart docker

check docker log:
sudo journalctl -fu docker.service

No comments:

Post a Comment