Docker
Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications.
http://www.zdnet.com/article/what-is-docker-and-why-is-it-so-darn-popular/
Developers can use Docker to pack, ship, and run any application as a lightweight, portable, self sufficient LXC container that can run virtually anywhere.
In a nutshell, here's what Docker can do for you: It can get more applications running on the same hardware than other technologies; it makes it easy for developers to quickly create, ready-to-run containered applications; and it makes managing and deploying applications much easier.
http://en.wikipedia.org/wiki/LXC
LXC (Linux Containers) is an operating system–level virtualization method for running multiple isolated Linux systems (containers) on a single control host.
LXC provides operating system-level virtualization through a virtual environment that has its own process and network space, instead of creating a full-fledged virtual machine.
Tutorial
https://docs.docker.com/installation
https://docs.docker.com/articles/basics/
Windows install
https://docs.docker.com/installation/windows/
The Docker Engine uses Linux-specific kernel features, so to run it on Windows we need to use a lightweight virtual machine (vm).
docker run hello-world
Docker SSH container Ubuntu
https://docs.docker.com/examples/running_ssh_service/
In bootDocker create ~/ssh/Dockerfile :
# sshd # # VERSION 0.0.2 FROM ubuntu:14.04 MAINTAINER Sven Dowideit <SvenDowideit@docker.com> RUN apt-get update && apt-get install -y openssh-server RUN mkdir /var/run/sshd RUN echo 'root:screencast' | chpasswd RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config # SSH login fix. Otherwise user is kicked off after login RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd ENV NOTVISIBLE "in users profile" RUN echo "export VISIBLE=now" >> /etc/profile EXPOSE 22 CMD ["/usr/sbin/sshd", "-D"]
- docker build -t eg_sshd .
- docker run -d -P --name test_sshd eg_sshd
- docker ps -l
ssh root@127.0.0.1 -p49153 # password screencast
- sudo docker stop test_sshd # stop container test_sshd
Install jdk8 in trusty
- apt-get install software-properties-common
- add-apt-repository ppa:openjdk-r/ppa -y
- apt-get update
- apt-get install openjdk-8-jdk
Dockerfile
FROM ubuntu:14.04 RUN apt-get update && \ apt-get install -y traceroute openssh-server software-properties-common mongodb rabbitmq-server && \ add-apt-repository ppa:openjdk-r/ppa -y && \ apt-get update && \ apt-get install -y openjdk-8-jdk RUN mkdir /var/run/sshd RUN echo 'root:12345678' | chpasswd RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config # SSH login fix. Otherwise user is kicked off after login RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd ENV NOTVISIBLE "in users profile" RUN echo "export VISIBLE=now" >> /etc/profile EXPOSE 22 8080 8081 8082 5672 15672 27017 80 CMD ["/usr/sbin/sshd", "-D"]
Install Docker CE slack 64 14.2
Install go lang
cd /tmp wget https://slackbuilds.org/slackbuilds/14.2/development/google-go-lang.tar.gz tar xvzf google-go-lang.tar.gz cd google-go-lang wget https://storage.googleapis.com/golang/go1.10.1.src.tar.gz change slackbuild to use 1.10.1 ./google-go-lang.SlackBuild installpkg /tmp/google-go-lang-1.9.5-x86_64-1_SBo.tgz go --version In ~/.bashrc export GOPATH="$HOME:/usr/share/gocode" go help buildmode go get golang.org/x/tools/cmd/godoc remove support to gcc-go ! /usr/lib64/go1.10.1/go/bin/ /usr/lib64/go1.10.1/go/bin/go version # in ~/.bashrc export PATH="$PATH:/usr/lib64/go1.10.1/go/bin/"
Install docker-proxy
cd /tmp wget https://slackbuilds.org/slackbuilds/14.2/system/docker-proxy.tar.gz tar xvzf docker-proxy.tar.gz cd docker-proxy wget https://github.com/docker/libnetwork/archive/1b91bc9/libnetwork-1b91bc94094ecfdae41daa465cc0c8df37dfb3dd.tar.gz ./docker-proxy.SlackBuild installpkg /tmp/docker-proxy-20180314_1b91bc9-x86_64-1_SBo.tgz
Install tini
cd /tmp wget https://slackbuilds.org/slackbuilds/14.2/system/tini.tar.gz tar xvzf tini.tar.gz cd tini wget https://github.com/krallin/tini/archive/949e6fa/tini-949e6facb77383876aeff8a6944dde66b3089574.tar.gz ./tini.SlackBuild installpkg /tmp/tini-0.13.0_949e6fa-x86_64-1_SBo.tgz
Install libseccomp
cd /tmp wget https://slackbuilds.org/slackbuilds/14.2/libraries/libseccomp.tar.gz tar xvzf libseccomp.tar.gz cd libseccomp wget https://github.com/seccomp/libseccomp/archive/v2.3.3/libseccomp-2.3.3.tar.gz ./libseccomp.SlackBuild installpkg /tmp/libseccomp-2.3.3-x86_64-1_SBo.tgz
Install runc
cd /tmp wget https://slackbuilds.org/slackbuilds/14.2/system/runc.tar.gz tar xvzf runc.tar.gz cd runc wget https://github.com/opencontainers/runc/archive/v1.0.0-rc5/runc-1.0.0-rc5.tar.gz ./runc.SlackBuild installpkg /tmp/runc-1.0.0_rc5-x86_64-1_SBo.tgz
Install containerd
cd /tmp wget https://slackbuilds.org/slackbuilds/14.2/system/containerd.tar.gz tar xvzf containerd.tar.gz cd containerd wget https://github.com/containerd/containerd/archive/v1.0.2/containerd-1.0.2.tar.gz ./containerd.SlackBuild installpkg /tmp/containerd-1.0.2-x86_64-1_SBo.tgz
Install docker
cd /tmp wget https://slackbuilds.org/slackbuilds/14.2/system/docker.tar.gz tar xvzf docker.tar.gz cd docker wget https://github.com/docker/docker-ce/archive/v18.03.0-ce/docker-ce-18.03.0-ce.tar.gz ./docker.SlackBuild installpkg /tmp/docker-18.03.0-x86_64-1_SBo.tgz Added option --userland-proxy=false in /etc/rc.d/rc.docker variable DOCKER_OPTS="--userland-proxy=false" cd /etc/rc.d sh rc.docker status sh rc.docker start
Docker image with SSH Ubuntu Xenial 16.04
Adapted from https://docs.docker.com/engine/examples/running_ssh_service/
Dockerfile:
# https://docs.docker.com/engine/examples/running_ssh_service/ FROM ubuntu:16.04 RUN apt-get update && apt-get install -y openssh-server RUN mkdir /var/run/sshd RUN echo 'root:screencast' | chpasswd RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config # SSH login fix. Otherwise user is kicked off after login RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd ENV NOTVISIBLE "in users profile" RUN echo "export VISIBLE=now" >> /etc/profile RUN useradd userx RUN echo 'userx:userx' | chpasswd EXPOSE 22 CMD ["/usr/sbin/sshd", "-D"]
Steps:
docker build -t docker_test . docker run -d -P --name test_container1 docker_test docker ps -a ssh root@127.0.0.1 -p32771 useradd userx echo 'userx:userx' | chpasswd ssh userx@127.0.0.1 -p32771 docker container stop test_container1 docker container rm test_container1 docker image rm docker_test
Install Docker in Ubuntu Xenial (16.04.4) vagrant box
1 mkdir tmp
2 cd tmp
3 vagrant init ubuntu/xenial64
4 vagrant up
5 vagrant ssh
6 # inside the box with user vagrant
7 sudo bash
8 apt-get update
9 apt-get install apt-transport-https ca-certificates curl software-properties-common
10 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
11 apt-key fingerprint 0EBFCD88
12 add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
13 apt-get update
14 apt-get install docker-ce
15 docker run hello-world
16 usermod -aG docker
17 exit
18 exit
19 #login again with vagrant ssh
20 # as user vagrant
21 docker run hello-world
22 # install java and maven
23 apt-get install openjdk-8-jdk
24 apt-get install maven
Commands
1 docker ps -a # showall containers
2 docker system prune -a # clean system
3 docker ps -a | awk '//{print $1}' | grep -v "CONTAINER" | xargs -i sh -c 'docker stop {};docker rm {}' # clear all containers
4 docker build -t acme_app . # build image from docker file
5 docker run -P -p 8080:80 -d acme_app # run dettached container from image acme_app mapping port 8080 to port exposed 80
6
Docker DNS server
As of Docker 1.10, the docker daemon implements an embedded DNS server which provides built-in service discovery for any container created with a valid name or net-alias or aliased by link. So you should not assume the way the files such as /etc/hosts, /etc/resolv.conf are managed inside the containers and leave the files alone and use the following Docker options instead. Note: The DNS server is always at 127.0.0.11.
Docker container based on GCC image
Docker playground
FROM ubuntu:16.04 RUN apt-get update && apt-get install -y openssh-server RUN mkdir /var/run/sshd RUN echo 'root:screencast' | chpasswd RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config # SSH login fix. Otherwise user is kicked off after login RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd ENV NOTVISIBLE "in users profile" RUN echo "export VISIBLE=now" >> /etc/profile RUN useradd userx RUN echo 'userx:userx' | chpasswd EXPOSE 22 CMD ["/usr/sbin/sshd", "-D"]
- docker build -t acme_app . # build image from docker file
- docker run -P -p 8080:80 -d acme_app # run dettached container from image acme_app mapping port 8080 to port exposed 80
- docker ps
- docker exec -it 8682f5c53f30 bash
- apt install -y net-tools openjdk-8-jdk maven git links vim nano
mkdir -p src/main/java/hello/ mkdir -p src/main/resources/templates/ mkdir -p src/main/resources/ nano pom.xml nano src/main/java/hello/GreetingController.java nano src/main/java/hello/Application.java nano src/main/java/hello/ThreadTimer.java nano src/main/java/hello/WaitThread.java nano src/main/java/hello/Dummy.java nano package hello; nano src/main/java/hello/DummyDAO.java nano src/main/resources/templates/greeting.html nano src/main/resources/application.properties nano src/main/resources/logback-spring.xml nano src/main/resources/test.sql mvn clean install
apt install git git clone https://github.com/vborrego/testSpringThymeleaf.git export JAVA_HOME=/usr cd / wget http://mirrors.up.pt/pub/apache/tomcat/tomcat-9/v9.0.22/bin/apache-tomcat-9.0.22.tar.gz tar xvzf apache-tomcat-9.0.22.tar.gz cd apache-tomcat-9.0.22/bin/ ./startup.sh cp /root/testSpringThymeleaf/target/testSpringMVCThymeleaf-0.1.0.war webapps/ cd /testSpringThymeleaf/ mvn clean install cp target/testSpringMVCThymeleaf-0.1.0.war /apache-tomcat-9.0.22/webapps/ links http://localhost:8080
wget https://pypi.python.org/packages/source/C/CherryPy/CherryPy-3.2.4.tar.gz cp CherryPy-3.2.4.tar.gz /tmp cd /tmp tar xvzf CherryPy-3.2.4.tar.gz apt install python libapache2-mod-wsgi apache2 -y cd CherryPy-3.2.4 python setup.py build python setup.py install mkdir -p /var/www/htdocs/cherrypytest/static vi /var/www/htdocs/cherrypytest/cherrypytest.wsgi echo "Static Test" > /var/www/htdocs/cherrypytest/static/a.txt service apache2 start cd /etc/apache2/sites-available/ vi 001-cherry.conf ln -s /etc/apache2/sites-available/001-cherry.conf /etc/apache2/sites-enabled/001-cherry.conf service apache2 restart service apache2 restart links http://localhostcherrypytest/ # 127.0.0.1 localhostcherrypytest in /etc/hosts cat /etc/apache2/sites-available/001-cherry.conf <VirtualHost *:80> ServerName localhostcherrypytest DocumentRoot "/var/www/htdocs/cherrypytest" WSGIScriptAlias / /var/www/htdocs/cherrypytest/cherrypytest.wsgi <Directory "/var/www/htdocs/cherrypytest"> Require local </Directory> </VirtualHost> root@ef4b410a02b4:/etc/apache2/sites-available# cat 000-default.conf<VirtualHost *:80> ServerName localhost DocumentRoot "/var/www/htdocs/cherrypytest" WSGIScriptAlias / /var/www/htdocs/cherrypytest/cherrypytest.wsgi <Directory "/var/www/htdocs/cherrypytest"> Require local </Directory> </VirtualHost>