Install docker on Ubuntu
Installation guild is in:
1.
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
2.
wget
https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/
docker-ce_17.06.0~ce-0~ubuntu_amd64.deb --verbose
-P /tmp
3.
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.
Solution:
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 https://registry-1.docker.io/v2/: 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
Solution:
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo
vim
/etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=YOUR_PROXY"
"HTTPS_PROXY=YOUR_PROXY"
"http_proxy=YOUR_PORXY"
"https_proxy=YOUR_PROXY" "no_proxy=localhost,192.168.33.11,127.0.0.1"
"NO_PROXY=localhost,192.168.33.11,127.0.0.1"
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/logging.properties
-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
-Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap
start
Go inside the container:
sudo
docker exec -it mytomcat1 /bin/sh
#pwd
(working directory from Dockerfile)
Find out the processing running inside docker:
#
ps -fwww 1
UID PID
PPID C STIME TTY STAT
TIME CMD
root 1
0 1 07:40 ? Ssl
0:03 /docker-java-home/jre/bin/java
-Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
-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
-Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap
start
#cd
logs
#touch
abc.abc
#exit
Restart and go inside mytomcat1,
logs/abc.abc
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