| 
  
   Size: 26332 
  
  Comment:  
 | 
    ← Revision 99 as of 2023-11-23 13:36:48  ⇥ 
  Size: 36527 
  
  Comment:  
 | 
| Deletions are marked like this. | Additions are marked like this. | 
| Line 1: | Line 1: | 
| <<TableOfContents(2)>> | 
|
| Line 30: | Line 32: | 
| == Hello world == {{{#!highlight sh  | 
|
| Line 31: | Line 35: | 
| }}} | |
| Line 37: | Line 41: | 
| {{{ | {{{#!highlight sh | 
| Line 60: | Line 64: | 
|  * 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  | 
{{{#!highlight sh 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 }}}  | 
| Line 67: | Line 73: | 
|  * apt-get install software-properties-common * add-apt-repository ppa:openjdk-r/ppa -y * apt-get update * apt-get install openjdk-8-jdk  | 
{{{#!highlight sh apt-get install software-properties-common add-apt-repository ppa:openjdk-r/ppa -y apt-get update apt-get install openjdk-8-jdk }}}  | 
| Line 73: | Line 81: | 
| {{{ | {{{#!highlight sh | 
| Line 94: | Line 102: | 
}}} = Install Docker CE slack 64 14.2 =  | 
}}} == Install Docker CE slack 64 14.2 ==  | 
| Line 100: | Line 107: | 
| == Install go lang == {{{  | 
=== Install go lang === {{{#!highlight sh  | 
| Line 107: | Line 114: | 
| change slackbuild to use 1.10.1 | # change slackbuild to use 1.10.1 | 
| Line 109: | Line 116: | 
| installpkg /tmp/google-go-lang-1.9.5-x86_64-1_SBo.tgz | # installpkg /tmp/google-go-lang-1.9.5-x86_64-1_SBo.tgz | 
| Line 112: | Line 119: | 
| In ~/.bashrc | # In ~/.bashrc | 
| Line 117: | Line 124: | 
| remove support to gcc-go ! | # remove support to gcc-go ! | 
| Line 125: | Line 132: | 
| == Install docker-proxy == {{{  | 
=== Install docker-proxy === {{{#!highlight sh  | 
| Line 136: | Line 143: | 
| == Install tini == {{{  | 
=== Install tini === {{{#!highlight sh  | 
| Line 147: | Line 154: | 
| == Install libseccomp == {{{  | 
=== Install libseccomp === {{{#!highlight sh  | 
| Line 158: | Line 165: | 
| == Install runc == {{{  | 
=== Install runc === {{{#!highlight sh  | 
| Line 169: | Line 176: | 
| == Install containerd == {{{  | 
=== Install containerd === {{{#!highlight sh  | 
| Line 180: | Line 187: | 
| == Install docker == {{{  | 
=== Install docker === {{{#!highlight sh  | 
| Line 190: | Line 197: | 
| Added option --userland-proxy=false in /etc/rc.d/rc.docker variable | # Added option --userland-proxy=false in /etc/rc.d/rc.docker variable | 
| Line 202: | Line 209: | 
| {{{ | {{{#!highlight sh | 
| Line 224: | Line 231: | 
| {{{ | {{{#!highlight sh | 
| Line 232: | Line 239: | 
| docker exec -it test_container1 /bin/bash | |
| Line 238: | Line 246: | 
| {{{#!highlight bash | {{{#!highlight sh | 
| Line 263: | Line 271: | 
}}}  | 
}}} | 
| Line 268: | Line 274: | 
| {{{#!highlight bash | {{{#!highlight sh | 
| Line 270: | Line 276: | 
| docker system prune -a # clean system | # clean system including volumes without asking for permission docker system prune -a -f --volumes  | 
| Line 287: | Line 294: | 
| {{{#!highlight bash | {{{#!highlight sh | 
| Line 299: | Line 306: | 
| {{{#!highlight bash | {{{#!highlight sh | 
| Line 305: | Line 312: | 
| # curl -X POST -d "{\"name\":\"jkl\"}" http://localhost:1234/hellojson --header "Content-Type:application/json" | |
| Line 336: | Line 344: | 
|        # curl "http://localhost:1234/add/2/100" # curl "http://localhost:1234/add?param1=2¶m2=100" print "Called add"  | 
|
| Line 342: | Line 353: | 
| # curl -X POST -d "{\"name\":\"jkl\"}" http://localhostcherrypytest/hellojson --header "Content-Type:application/json" |         # curl -X POST -d "{\"name\":\"jkl\"}" http://localhostcherrypytest/hellojson --header "Content-Type:application/json" # curl -X POST -d "{\"name\":\"jkl\"}" http://localhost:1234/hellojson --header "Content-Type:application/json"  | 
| Line 352: | Line 364: | 
| }}} === Execute === {{{#!highlight sh docker build -t docker-cherrypy-image . docker run -it -P --rm --name docker-cherrypy-container docker-cherrypy-image docker ps docker exec -it docker-cherrypy-container bash # in container curl -vv localhost docker run -it -p 1234:80 --rm --name docker-cherrypy-container docker-cherrypy-image curl -vv localhost:1234  | 
|
| Line 367: | Line 392: | 
| {{{#!highlight bash | {{{#!highlight sh | 
| Line 377: | Line 402: | 
| {{{#!highlight bash | {{{#!highlight sh | 
| Line 443: | Line 468: | 
| {{{#!highlight bash | {{{#!highlight sh | 
| Line 454: | Line 479: | 
| {{{#!highlight bash | {{{#!highlight sh | 
| Line 460: | Line 485: | 
|  * touch Dockerfile * touch pom.xml * mkdir -p src/main/java/hello/ * mkdir -p src/main/resources/templates/ * touch src/main/java/hello/GreetingController.java * touch src/main/java/hello/Application.java * touch src/main/java/hello/ThreadTimer.java * touch src/main/java/hello/WaitThread.java * touch src/main/java/hello/Dummy.java * touch src/main/resources/templates/greeting.html * touch src/main/resources/application.properties * touch src/main/resources/logback-spring.xml * mvn clean install * java -Dfilelog=/tmp/out.log -jar target/test-spring-boot-0.1.0.jar * http://localhost:8080/greeting  | 
{{{#!highlight sh touch Dockerfile touch pom.xml mkdir -p src/main/java/hello/ mkdir -p src/main/resources/templates/ touch src/main/java/hello/GreetingController.java touch src/main/java/hello/Application.java touch src/main/java/hello/ThreadTimer.java touch src/main/java/hello/WaitThread.java touch src/main/java/hello/Dummy.java touch src/main/resources/templates/greeting.html touch src/main/resources/application.properties touch src/main/resources/logback-spring.xml mvn clean install java -Dfilelog=/tmp/out.log -jar target/test-spring-boot-0.1.0.jar # http://localhost:8080/greeting }}}  | 
| Line 477: | Line 504: | 
| {{{ | {{{#!highlight sh | 
| Line 809: | Line 836: | 
| {{{#!highlight bash | {{{#!highlight sh | 
| Line 860: | Line 887: | 
== Docker registry == * https://hub.docker.com/_/registry {{{#!highlight bash # local registry CONTAINER_NAME=registry IMAGE_NAME=registry:2 docker run -d -p 5000:5000 --restart always --name $CONTAINER_NAME $IMAGE_NAME }}} * Check images catalog in registry * http://hostx:5000/v2/_catalog * http://hostx:5000/v2/image/tags/list == Bind mount == * https://docs.docker.com/storage/bind-mounts/ When you use a bind mount, a file or directory on the host machine is mounted into a container. {{{#!highlight sh docker run -d \ -it \ --name devtest \ --mount type=bind,source="$(pwd)"/target,target=/app \ nginx:latest }}} == Install docker in nb200 (32 bit) == {{{#!highlight sh # install go 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.11.13.src.tar.gz nano google-go-lang.SlackBuild ./google-go-lang.SlackBuild installpkg /tmp/google-go-lang-1.11.13-i586-1_SBo.tgz go --version nano ~/.bashrc go --version source . source ~/.bashrc go --version /usr/lib/go1.11.13/go/bin/go --version /usr/lib/go1.11.13/go/bin/go version go version nano ~/.bashrc source ~/.bashrc go version echo $PATH nano ~/.bashrc exit go version which go go help buildmode echo $PATH cat /root/.bashrc export PATH="$PATH:/usr/lib64/go1.11.13/go/bin/" go help buildmode go version echo $PATH go version removepkg gcc-go-5.5.0-i586-1_slack14.2 go version echo $PATH nano ~/.bashrc source ~/.bashrc go version cat ~/.bashrc # 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/2cfbf9b/libnetwork-2cfbf9b1f98162a55829a21cc603c76072a75382.tar.gz ./docker-proxy.SlackBuild installpkg/tmp/docker-proxy-20181207_2cfbf9b-i586-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/v0.18.0/tini-0.18.0.tar.gz ./tini.SlackBuild installpkg/tmp/tini-0.18.0-i586-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.4.2/libseccomp-2.4.2.tar.gz ./libseccomp.SlackBuild installpkg/tmp/libseccomp-2.4.2-i586-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/8084f76/runc-8084f7611e4677174c8dbeb17152f3390fa41952.tar.gz ./runc.SlackBuild installpkg /tmp/runc-1.0.0_rc6_8084f76-i586-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.2.4/containerd-1.2.4.tar.gz ./containerd.SlackBuild installpkg/tmp/containerd-1.2.4-i586-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.09.2/docker-ce-18.09.2.tar.gz vi docker.SlackBuild # change to docker-linux-386 ./docker.SlackBuild installpkg /tmp/docker-18.09.2-i586-1_SBo.tgz cd /etc/rc.d sh rc.docker status sh rc.docker start groupadd -r -g 281 docker usermod -a -G docker vitor }}} == Docker + cherrypy == === Setup environment === {{{#!highlight python cd ~ mkdir env-docker-cherry cd env-docker-cherry touch Dockerfile mkdir target touch target/cherry.py }}} === Ubuntu Dockerfile === {{{#!highlight sh FROM ubuntu:20.04 RUN apt update RUN apt-get install -y curl sudo wget python net-tools vim RUN mkdir /app RUN cd /app && curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py RUN cd app/ && python get-pip.py && pip install cherrypy RUN echo "#!/bin/sh\n python /app/cherry.py" > /start.sh EXPOSE 80 22 8080 8081 CMD ["sh","/start.sh"] }}} === Alpine Dockerfile === {{{#!highlight sh touch Dockerfile mkdir target touch target/cherry.py }}} {{{#!highlight sh FROM alpine:3.16 RUN apk add --update --no-cache python3 curl wget RUN mkdir /app RUN cd /app && curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py RUN cd app/ && python3 get-pip.py && pip install cherrypy EXPOSE 80 22 8080 8081 CMD ["python3","/app/cherry.py"] }}} === target/cherry.py === {{{#!highlight python import cherrypy import json cherrypy.config.update({'server.socket_port': 8081}) cherrypy.config.update({'server.socket_host': '0.0.0.0'}) class Root(object): @cherrypy.expose def index(self): return "Hello World!".encode('utf8') root = Root() cherrypy.quickstart(root) }}} === Commands to run container === {{{#!highlight sh docker build -t env-docker-cherry-image . # run container and map docker internal port 8081 to external port 8081 docker run -p 8081:8081 -d -it --rm --name env-docker-cherry-container --mount type=bind,source="$(pwd)"/target,target=/app env-docker-cherry-image docker ps # invoke external port 8081 curl http://localhost:8081/ # change code in target ... vi target/cherry.py # inside Root class # @cherrypy.expose # def test(self): # return "test hey!".encode('utf8') # invoke external port 8081 to check the modification made curl http://localhost:8081/test #### create net between two containers docker network create testnet docker network ls docker network connect testnet env-docker-cherry-container docker run -p 8082:8081 -d -it --rm --name env-docker-cherry-container-2 --network testnet --mount type=bind,source="$(pwd)"/target,target=/app env-docker-cherry-image docker ps docker exec -it env-docker-cherry-container-2 ash # ping env-docker-cherry-container-2 # ping env-docker-cherry-container docker exec -it env-docker-cherry-container ash # ping env-docker-cherry-container-2 # ping env-docker-cherry-container }}} == Setup Proxy for docker daemon == {{{#!highlight sh sudo bash mkdir /etc/systemd/system/docker.service.d cd /etc/systemd/system/docker.service.d nano http-proxy.conf [Service] Environment="HTTP_PROXY=http://192.168.22.214:3128" Environment="HTTPS_PROXY=http://192.168.22.214:3128" systemctl daemon-reload systemctl restart docker # settings also in ~/.docker/config.json { "proxies": { "default": { "httpProxy": "http://192.168.42.108:3128", "httpsProxy": "http://192.168.42.108:3128", "noProxy": "127.0.0.0/8" } } } }}} == Install from binaries in Slackware 15.0 == {{{#!highlight sh # as root wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.17.tgz tar xvzf docker-20.10.17.tgz cp docker/* /usr/bin/ groupadd -r -g 281 docker usermod -a -G docker vitor # signout and signin user vitor sudo nohup dockerd & docker run hello-world }}} == Build image from scratch - Slackware64 15.0 - rootfs == === Dockerfile === {{{#!highlight sh FROM scratch ADD . / RUN /usr/bin/echo "test" > /test.txt #CMD ["/usr/bin/cat","/test.txt"] CMD ["/usr/bin/tail","-f","/test.txt"] }}} === Steps === {{{#!highlight sh mkdir scratch-test cd scratch-test/ touch Dockerfile mkdir -p usr/bin/ mkdir lib64 mkdir bin cp /usr/bin/ls usr/bin/ cp /usr/bin/cat usr/bin/ cp /usr/bin/echo usr/bin/ cp /usr/bin/tail usr/bin/ cp /usr/bin/uname usr/bin/ cp /bin/sh bin/ # to check dependencies use ldd cp /lib64/libcap.so.2 lib64/ cp /lib64/libc.so.6 lib64/ cp /lib64/libtinfo.so.6 lib64/ cp /lib64/libdl.so.2 lib64/ cp /lib64/ld-linux-x86-64.so.2 lib64/ # build image and run container docker build -t scratch-test-image . docker run --rm --name scratch-test-container scratch-test-image ##### docker build -t scratch-test-image . docker run -d --rm --name scratch-test-container scratch-test-image docker ps docker exec -it scratch-test-container sh # export container filesystem docker container export scratch-test-container -o scratch-test.tar tar tvf scratch-test.tar.gz }}} == Static binaries in Slackware64 == * https://docs.docker.com/engine/install/binaries/ * https://download.docker.com/linux/static/stable/x86_64/docker-20.10.17.tgz === /etc/rc.d/rc.docker === {{{#!highlight sh #!/bin/sh PATH=$PATH:/usr/sbin docker_start() { /usr/bin/dockerd --raw-logs > /var/log/dockerd.log 2>&1 & } docker_stop() { killall dockerd } docker_restart() { docker_stop docker_start } case "$1" in 'start') docker_start ;; 'stop') docker_stop ;; 'restart') docker_restart ;; *) echo "usage $0 start|stop|restart" esac }}} {{{#!highlight sh # In Slack64 sudo sh /etc/rc.d/rc.docker start #sudo sh /etc/rc.d/rc.docker stop #sudo sh /etc/rc.d/rc.docker restart docker ps docker version docker run hello-world }}}  | 
Contents
- 
Docker
- Tutorial
 - Windows install
 - Hello world
 - Docker SSH container Ubuntu
 - Install jdk8 in trusty
 - Install Docker CE slack 64 14.2
 - Docker image with SSH Ubuntu Xenial 16.04
 - Install Docker in Ubuntu Xenial (16.04.4) vagrant box
 - Commands
 - Docker DNS server
 - Docker container based on GCC image
 - Docker playground - cherrypy
 - Docker - openjdk8 - hello
 - Docker - openjdk 8 - hello - maven
 - docker - maven - springboot-test
 - Docker registry
 - Bind mount
 - Install docker in nb200 (32 bit)
 - Docker + cherrypy
 - Setup Proxy for docker daemon
 - Install from binaries in Slackware 15.0
 - Build image from scratch - Slackware64 15.0 - rootfs
 - Static binaries in Slackware64
 
 
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).
Hello world
   1 docker run hello-world
Docker SSH container Ubuntu
https://docs.docker.com/examples/running_ssh_service/
In bootDocker create ~/ssh/Dockerfile :
   1 # sshd
   2 #
   3 # VERSION               0.0.2
   4 
   5 FROM ubuntu:14.04
   6 MAINTAINER Sven Dowideit <SvenDowideit@docker.com>
   7 
   8 RUN apt-get update && apt-get install -y openssh-server
   9 RUN mkdir /var/run/sshd
  10 RUN echo 'root:screencast' | chpasswd
  11 RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
  12 
  13 # SSH login fix. Otherwise user is kicked off after login
  14 RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
  15 
  16 ENV NOTVISIBLE "in users profile"
  17 RUN echo "export VISIBLE=now" >> /etc/profile
  18 
  19 EXPOSE 22
  20 CMD ["/usr/sbin/sshd", "-D"]
Install jdk8 in trusty
Dockerfile
   1 FROM ubuntu:14.04
   2 
   3 RUN apt-get update && \
   4     apt-get install -y traceroute openssh-server software-properties-common mongodb rabbitmq-server  && \
   5     add-apt-repository ppa:openjdk-r/ppa -y && \
   6     apt-get update && \
   7     apt-get install -y openjdk-8-jdk
   8 
   9 RUN mkdir /var/run/sshd
  10 RUN echo 'root:12345678' | chpasswd
  11 RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
  12 
  13 # SSH login fix. Otherwise user is kicked off after login
  14 RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
  15 
  16 ENV NOTVISIBLE "in users profile"
  17 RUN echo "export VISIBLE=now" >> /etc/profile
  18 
  19 EXPOSE 22 8080 8081 8082 5672 15672 27017 80
  20 CMD ["/usr/sbin/sshd", "-D"]
Install Docker CE slack 64 14.2
Install go lang
   1 cd /tmp
   2 wget https://slackbuilds.org/slackbuilds/14.2/development/google-go-lang.tar.gz
   3 tar xvzf google-go-lang.tar.gz
   4 cd google-go-lang
   5 wget https://storage.googleapis.com/golang/go1.10.1.src.tar.gz
   6 # change slackbuild to use 1.10.1
   7 ./google-go-lang.SlackBuild
   8 # installpkg /tmp/google-go-lang-1.9.5-x86_64-1_SBo.tgz
   9 go --version 
  10 
  11 # In ~/.bashrc 
  12 export GOPATH="$HOME:/usr/share/gocode"
  13 go help buildmode
  14 go get golang.org/x/tools/cmd/godoc
  15 
  16 # remove support to gcc-go !
  17 
  18 /usr/lib64/go1.10.1/go/bin/
  19 /usr/lib64/go1.10.1/go/bin/go version
  20 # in ~/.bashrc
  21 export PATH="$PATH:/usr/lib64/go1.10.1/go/bin/"
Install docker-proxy
   1 cd /tmp
   2 wget https://slackbuilds.org/slackbuilds/14.2/system/docker-proxy.tar.gz
   3 tar xvzf docker-proxy.tar.gz
   4 cd docker-proxy
   5 wget https://github.com/docker/libnetwork/archive/1b91bc9/libnetwork-1b91bc94094ecfdae41daa465cc0c8df37dfb3dd.tar.gz
   6 ./docker-proxy.SlackBuild 
   7 installpkg /tmp/docker-proxy-20180314_1b91bc9-x86_64-1_SBo.tgz
Install tini
Install libseccomp
Install runc
Install containerd
Install docker
   1 cd /tmp
   2 wget https://slackbuilds.org/slackbuilds/14.2/system/docker.tar.gz
   3 tar xvzf docker.tar.gz
   4 cd docker 
   5 wget https://github.com/docker/docker-ce/archive/v18.03.0-ce/docker-ce-18.03.0-ce.tar.gz
   6 ./docker.SlackBuild
   7 installpkg /tmp/docker-18.03.0-x86_64-1_SBo.tgz
   8 
   9 # Added option --userland-proxy=false in  /etc/rc.d/rc.docker variable 
  10 DOCKER_OPTS="--userland-proxy=false"
  11 
  12 cd /etc/rc.d
  13 sh rc.docker status
  14 sh rc.docker start
Docker image with SSH Ubuntu Xenial 16.04
Adapted from https://docs.docker.com/engine/examples/running_ssh_service/
Dockerfile:
   1 # https://docs.docker.com/engine/examples/running_ssh_service/
   2 FROM ubuntu:16.04
   3 
   4 RUN apt-get update && apt-get install -y openssh-server
   5 RUN mkdir /var/run/sshd
   6 RUN echo 'root:screencast' | chpasswd
   7 RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
   8 
   9 # SSH login fix. Otherwise user is kicked off after login
  10 RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
  11 
  12 ENV NOTVISIBLE "in users profile"
  13 RUN echo "export VISIBLE=now" >> /etc/profile
  14 RUN useradd userx
  15 RUN echo 'userx:userx' | chpasswd
  16 
  17 EXPOSE 22
  18 CMD ["/usr/sbin/sshd", "-D"]
Steps:
   1 docker build -t docker_test . 
   2 docker run -d -P --name test_container1 docker_test 
   3 docker ps -a
   4 ssh root@127.0.0.1 -p32771
   5 useradd userx
   6 echo 'userx:userx' | chpasswd
   7 ssh userx@127.0.0.1 -p32771
   8 docker exec -it test_container1 /bin/bash
   9 docker container stop test_container1
  10 docker container rm test_container1
  11 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 # clean system including volumes without asking for permission
   3 docker system prune -a -f --volumes 
   4 docker ps -a | awk '//{print $1}' | grep  -v "CONTAINER" | xargs -i sh -c 'docker stop {};docker rm {}'  # clear all containers
   5 docker build -t acme_app . # build image from docker file
   6 docker run -P -p 8080:80 -d acme_app # run dettached container from image acme_app mapping port 8080 to port exposed 80
   7 
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 - cherrypy
Dockerfile
   1 # docker build -t image_cherrypy . # build image from Dockerfile
   2 # docker run -P -p 8080:80 -d image_cherrypy
   3 # touch cherrypytest.wsgi
   4 # links http://localhost/add/3/4
   5 # curl -X POST -d "{\"name\":\"jkl\"}" http://localhost/hellojson --header "Content-Type:application/json"
   6 # curl -X POST -d "{\"name\":\"jkl\"}" http://localhost:1234/hellojson --header "Content-Type:application/json"
   7 FROM ubuntu:16.04
   8 RUN apt-get update && apt-get install -y python libapache2-mod-wsgi apache2 vim links net-tools nano curl wget
   9 RUN wget https://pypi.python.org/packages/source/C/CherryPy/CherryPy-3.2.4.tar.gz
  10 RUN cp CherryPy-3.2.4.tar.gz /tmp
  11 RUN cd /tmp && tar xvzf CherryPy-3.2.4.tar.gz
  12 RUN cd /tmp/CherryPy-3.2.4 && python setup.py build && python setup.py install
  13 RUN mkdir -p /var/www/htdocs/cherrypytest/static
  14 # copy cherrypytest.wsgi from where the Dockerfile is
  15 COPY cherrypytest.wsgi /var/www/htdocs/cherrypytest/cherrypytest.wsgi
  16 RUN echo "Static Test" > /var/www/htdocs/cherrypytest/static/a.txt
  17 RUN echo "<VirtualHost *:80>\nServerName localhost\nDocumentRoot \"/var/www/htdocs/cherrypytest\"\nWSGIScriptAlias / /var/www/htdocs/cherrypytest/cherrypytest.wsgi\n<Directory \"/var/www/htdocs/cherrypytest\">\nRequire all granted\n</Directory>\n</VirtualHost>" > /etc/apache2/sites-available/000-default.conf
  18 RUN echo "#!/bin/sh\n service apache2 start \n tail -f /var/log/apache2/error.log" > /start.sh
  19 EXPOSE 80
  20 CMD ["sh","/start.sh"]
cherrypytest.wsgi
   1 import sys
   2 sys.stdout = sys.stderr
   3 import cherrypy
   4 
   5 cherrypy.config.update({'environment': 'embedded'})
   6 
   7 class HelloWorld(object):
   8     @cherrypy.expose
   9     def index(self):
  10         return "Hello World CherryPy!!!!"
  11 
  12     @cherrypy.expose
  13     def add(self,param1,param2):
  14        # curl "http://localhost:1234/add/2/100"
  15        # curl "http://localhost:1234/add?param1=2¶m2=100"
  16        print "Called add"
  17        return str( int(param1)+int(param2) )
  18 
  19     @cherrypy.expose
  20     @cherrypy.tools.json_in()
  21     @cherrypy.tools.json_out()
  22     def hellojson(self): 
  23         # curl -X POST -d "{\"name\":\"jkl\"}" http://localhostcherrypytest/hellojson --header "Content-Type:application/json"
  24         # curl -X POST -d "{\"name\":\"jkl\"}" http://localhost:1234/hellojson --header "Content-Type:application/json"
  25         inj = cherrypy.request.json
  26         return {"message": "hello world " + inj['name'] }
  27 
  28 hello = HelloWorld()    
  29 #static dir
  30 confx={'/static': {'tools.staticdir.on':True ,
  31                   'tools.staticdir.dir':'/var/www/htdocs/cherrypytest/static'
  32                   }}
  33 application = cherrypy.Application(hello, script_name=None, config=confx)
Execute
   1 docker build -t docker-cherrypy-image .
   2 docker run -it -P --rm --name docker-cherrypy-container docker-cherrypy-image 
   3 docker ps
   4 docker exec -it docker-cherrypy-container bash
   5 # in container
   6 curl -vv localhost
   7 
   8 docker run -it -p 1234:80 --rm --name docker-cherrypy-container docker-cherrypy-image
   9 curl -vv localhost:1234
Docker - openjdk8 - hello
Main.java
Dockerfile
Execute
Docker - openjdk 8 - hello - maven
- mkdir -p src/main/java/com/example/artifactX
 
pom.xml
   1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   2         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
   3         http://maven.apache.org/maven-v4_0_0.xsd">
   4   <modelVersion>4.0.0</modelVersion>
   5   <groupId>com.example</groupId>
   6   <artifactId>artifactX</artifactId>
   7   <packaging>jar</packaging>
   8   <version>0.0.1</version>
   9   <name>artifactX</name>
  10   <url>http://maven.apache.org</url>
  11   <build>
  12     <plugins>
  13       <plugin>
  14         <artifactId>maven-assembly-plugin</artifactId>
  15         <version>2.4</version>
  16         <configuration>
  17           <descriptorRefs>
  18             <descriptorRef>jar-with-dependencies</descriptorRef>
  19           </descriptorRefs>
  20           <archive>
  21             <manifest>
  22               <mainClass>com.example.artifactX.Main</mainClass>
  23             </manifest>
  24           </archive>
  25         </configuration>
  26         <executions>
  27           <execution>
  28             <id>make-assembly</id> 
  29             <phase>package</phase> 
  30             <goals>
  31               <goal>single</goal>
  32             </goals>
  33           </execution>
  34         </executions>
  35       </plugin>
  36     </plugins>
  37   </build>
  38   <dependencies>
  39   </dependencies>
  40 </project>
src/main/java/com/example/artifactX/Main.java
Dockerfile
Execute
docker - maven - springboot-test
   1 touch Dockerfile
   2 touch pom.xml
   3 mkdir -p src/main/java/hello/
   4 mkdir -p src/main/resources/templates/
   5 touch src/main/java/hello/GreetingController.java
   6 touch src/main/java/hello/Application.java
   7 touch src/main/java/hello/ThreadTimer.java
   8 touch src/main/java/hello/WaitThread.java
   9 touch src/main/java/hello/Dummy.java
  10 touch src/main/resources/templates/greeting.html
  11 touch src/main/resources/application.properties
  12 touch src/main/resources/logback-spring.xml
  13 mvn clean install
  14 java -Dfilelog=/tmp/out.log -jar target/test-spring-boot-0.1.0.jar
  15 # http://localhost:8080/greeting
  16 
Dockerfile
pom.xml
   1 <?xml version="1.0" encoding="UTF-8"?>
   2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   4     <modelVersion>4.0.0</modelVersion>
   5     <groupId>hello</groupId>
   6     <artifactId>test-spring-boot</artifactId>
   7     <version>0.1.0</version>
   8     <parent>
   9         <groupId>org.springframework.boot</groupId>
  10         <artifactId>spring-boot-starter-parent</artifactId>
  11         <version>1.4.0.RELEASE</version>
  12     </parent>
  13     <dependencies>
  14         <dependency>
  15             <groupId>org.springframework.boot</groupId>
  16             <artifactId>spring-boot-starter-thymeleaf</artifactId>
  17         </dependency>
  18     </dependencies>
  19     <properties>
  20         <start-class>hello.Application</start-class>
  21     </properties>
  22     <build>
  23         <plugins>
  24             <plugin>
  25                 <groupId>org.springframework.boot</groupId>
  26                 <artifactId>spring-boot-maven-plugin</artifactId>
  27             </plugin>
  28         </plugins>
  29     </build>
  30     <repositories>
  31         <repository>
  32             <id>spring-milestone</id>
  33             <url>http://repo.spring.io/libs-release</url>
  34         </repository>
  35     </repositories>
  36     <pluginRepositories>
  37         <pluginRepository>
  38             <id>spring-milestone</id>
  39             <url>http://repo.spring.io/libs-release</url>
  40         </pluginRepository>
  41     </pluginRepositories>
  42 </project>
src/main/java/hello/GreetingController.java
   1 package hello;
   2 
   3 import org.springframework.stereotype.Controller;
   4 import org.springframework.ui.Model;
   5 import org.springframework.web.bind.annotation.RequestMapping;
   6 import org.springframework.web.bind.annotation.RequestParam;
   7 import org.slf4j.Logger;
   8 import org.slf4j.LoggerFactory;
   9 import org.springframework.web.bind.annotation.ResponseBody;
  10 import org.springframework.beans.factory.annotation.Autowired;
  11 import java.util.List;
  12 import java.util.ArrayList;
  13 
  14 @Controller
  15 public class GreetingController {
  16     private final Logger logger = LoggerFactory.getLogger(GreetingController.class);
  17 
  18     public GreetingController(){
  19         logger.debug("Greeting controller created.");
  20     }
  21 
  22     @RequestMapping("/greeting")
  23     // http://localhost:8080/greeting?name=nnnn 
  24     public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
  25         logger.info("Greeting endpoint called.");
  26         model.addAttribute("name", name);
  27         return "greeting";
  28     }
  29 
  30     @RequestMapping(value="/dummy",produces="application/json")
  31     @ResponseBody
  32     // http://localhost:8080/dummy
  33     public List<Dummy> dummy(){
  34       List<Dummy> list= new java.util.ArrayList<Dummy>();
  35       Dummy dummy = new Dummy();
  36       dummy.setFieldA("AAA");
  37       dummy.setFieldB("CCC");
  38       list.add(dummy);
  39 
  40       Dummy dummy2 = new Dummy();
  41       dummy2.setFieldA("AAA2");
  42       dummy2.setFieldB("CCC2");
  43       list.add(dummy2);
  44 
  45       return list;
  46     }
  47 
  48 }
src/main/java/hello/Application.java
   1 package hello;
   2 
   3 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
   4 import org.springframework.boot.SpringApplication;
   5 import org.springframework.context.annotation.ComponentScan;
   6 import org.springframework.context.annotation.Bean;
   7 import org.springframework.beans.factory.annotation.Autowired;
   8 import org.springframework.beans.factory.annotation.Qualifier;
   9 import org.slf4j.Logger;
  10 import org.slf4j.LoggerFactory;
  11 
  12 @ComponentScan
  13 @EnableAutoConfiguration
  14 public class Application {
  15     private static Logger logger;
  16 
  17     public static void main(String[] args) {
  18         logger = LoggerFactory.getLogger(Application.class);
  19         logger.info("Starting application");
  20         SpringApplication.run(Application.class, args);
  21     }
  22 
  23 }
src/main/java/hello/ThreadTimer.java
   1 package hello;
   2 
   3 import org.springframework.stereotype.Component;
   4 import javax.annotation.PostConstruct;
   5 import org.springframework.beans.factory.annotation.Autowired;
   6 import java.text.MessageFormat;
   7 import org.slf4j.Logger;
   8 import org.slf4j.LoggerFactory;
   9 import java.util.ArrayList;
  10 
  11 @Component
  12 public class ThreadTimer extends Thread {
  13   private int delaySeconds;
  14   private Logger logger;
  15   private boolean running;
  16   private Object monitor=new Object();
  17   private ArrayList<Object> subscribers;
  18 
  19   //@Autowired
  20   //WaitThread waitThread;
  21 
  22   public ThreadTimer() {
  23     this.logger = LoggerFactory.getLogger(ThreadTimer.class);
  24     logger.info("Created instance of " + this.getClass().getSimpleName());
  25     this.running = true;
  26     this.delaySeconds = 5 * 1000;
  27     this.setName(this.getClass().getSimpleName() + "_" + this.getName());
  28     this.subscribers = new ArrayList<Object>();
  29   }
  30 
  31   public void addSubscriber(Object subscriber){
  32     this.subscribers.add(subscriber);
  33   }
  34 
  35   @PostConstruct
  36   public void init() {
  37     logger.info("Starting the thread");
  38     this.start();
  39   }
  40 
  41   @Override
  42   public void run() {
  43     while (running) {
  44       try {
  45         Thread.sleep(this.delaySeconds);
  46         logger.info("Delay " + this.getClass().getSimpleName());
  47 
  48         for(Object o: this.subscribers){
  49           synchronized(o){
  50             o.notify();
  51           }
  52         }
  53       }
  54       catch (InterruptedException e) {
  55           logger.info("ThreadTimer interrupted exception:" + e.getMessage() );
  56       }
  57       catch (Exception e) {
  58           e.printStackTrace();
  59           logger.info("ThreadTimer exception:" + e.getMessage() );
  60           stopRunning();
  61       }
  62     }
  63     logger.info("Exited " + this.getClass().getSimpleName());
  64   }
  65 
  66   public void startRunning() {
  67     this.running = true;
  68   }
  69 
  70   public void stopRunning() {
  71     this.running = false;
  72   }
  73 
  74   public void destroy(){
  75     logger.info("Called destroy");
  76     this.stopRunning();
  77     this.interrupt();
  78   }
  79 }
src/main/java/hello/WaitThread.java
   1 package hello;
   2 
   3 import org.springframework.stereotype.Component;
   4 import javax.annotation.PostConstruct;
   5 import java.text.MessageFormat;
   6 import org.slf4j.Logger;
   7 import org.slf4j.LoggerFactory;
   8 import org.springframework.beans.factory.annotation.Autowired;
   9 
  10 @Component
  11 public class WaitThread extends Thread {
  12   private Logger logger;
  13   private boolean running;
  14   private Object monitor;
  15 
  16   @Autowired
  17   ThreadTimer timerThread;
  18 
  19   public WaitThread() {
  20     this.logger = LoggerFactory.getLogger(WaitThread.class);
  21     logger.info("Created instance of " + this.getClass().getSimpleName());
  22     this.running = true;
  23     this.setName(this.getClass().getSimpleName() + "_" + this.getName());
  24     this.monitor=new Object();
  25   }
  26 
  27   @PostConstruct
  28   public void init() {
  29     this.timerThread.addSubscriber(this);
  30     logger.info("Starting the thread");
  31     this.start();
  32   }
  33 
  34   public void run() {
  35     while (running) {
  36       try {
  37         synchronized(this){
  38           this.wait();
  39           logger.info("Notification received.");
  40         }
  41       }
  42       catch (InterruptedException e) {
  43           logger.info("ThreadTimer interrupted exception:" + e.getMessage() );
  44       }
  45       catch (Exception e) {
  46           logger.info("WaitThread exception:" + e.getMessage() );
  47           stopRunning();
  48       }
  49     }
  50     logger.info("Exited " + this.getClass().getSimpleName());
  51   }
  52 
  53   public void startRunning() {
  54     this.running = true;
  55   }
  56 
  57   public void stopRunning() {
  58     this.running = false;
  59   }
  60 
  61   public void destroy(){
  62     logger.info("Called destroy");
  63     this.stopRunning();
  64     this.interrupt();
  65   }
  66 }
src/main/java/hello/Dummy.java
   1 package hello;
   2 
   3 public class Dummy{
   4   private String fieldA;
   5   private String fieldB;
   6 
   7   public Dummy(){
   8   }
   9 
  10   public String getFieldA(){
  11     return fieldA;
  12   }
  13 
  14   public String getFieldB(){
  15     return fieldB;
  16   }
  17 
  18   public void setFieldA(String arg){
  19     fieldA = arg;
  20   }
  21 
  22   public void setFieldB(String arg){
  23     fieldB = arg;
  24   }
  25 }
src/main/resources/templates/greeting.html
src/main/resources/application.properties
   1 logging.file=/tmp/testout.log
src/main/resources/logback-spring.xml
   1 <?xml version="1.0" encoding="UTF-8"?>
   2 <configuration>
   3 <!--
   4     <include resource="org/springframework/boot/logging/logback/defaults.xml" />
   5     <property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
   6     <include resource="org/springframework/boot/logging/logback/file-appender.xml" />
   7 -->
   8     <!-- override spring logback default behaviour -->
   9     <appender name="FILE" class="ch.qos.logback.core.FileAppender">
  10         <file>${filelog}</file>
  11         <encoder>
  12                 <pattern>%date{ISO8601} [%thread] %-5level %logger{35} - %msg%n</pattern>
  13         </encoder>
  14     </appender>
  15     <appender name="GREETFILE" class="ch.qos.logback.core.FileAppender">
  16         <file>/tmp/greet.log</file>
  17         <encoder>
  18                 <pattern>%date{ISO8601} [%thread] %-5level %logger{35} - %msg%n</pattern>
  19         </encoder>
  20     </appender>
  21     <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
  22         <layout class="ch.qos.logback.classic.PatternLayout">
  23                 <Pattern>%yellow(%date{ISO8601}) %green([%thread]) %highlight(%-5level) %cyan(%logger{35}) - %white(%msg%n) </Pattern>
  24         </layout>
  25     </appender>
  26     <root level="INFO">
  27         <appender-ref ref="FILE" />
  28         <appender-ref ref="CONSOLE"/>
  29     </root>
  30     <logger name="hello.GreetingController" level="debug" additivity="false">
  31         <appender-ref ref="GREETFILE"/>
  32         <appender-ref ref="CONSOLE" />
  33     </logger>
  34 </configuration>
Execute
- docker build -t hello-springboot-docker-image .
 - docker run -P -p 8080:8080 --name hello-springboot-docker -d hello-springboot-docker-image
 - docker ps
 - docker exec -it 5ea9eaff4616 /bin/ash
 - docker exec -it 5ea9eaff4616 /bin/sh
 
Docker registry
- Check images catalog in registry
 
Bind mount
When you use a bind mount, a file or directory on the host machine is mounted into a container.
Install docker in nb200 (32 bit)
   1 # install go
   2 cd /tmp
   3 wget https://slackbuilds.org/slackbuilds/14.2/development/google-go-lang.tar.gz
   4 tar xvzf google-go-lang.tar.gz
   5 cd google-go-lang
   6 wget https://storage.googleapis.com/golang/go1.11.13.src.tar.gz
   7 nano google-go-lang.SlackBuild 
   8 ./google-go-lang.SlackBuild
   9 installpkg /tmp/google-go-lang-1.11.13-i586-1_SBo.tgz 
  10 go --version
  11 nano ~/.bashrc
  12 go --version
  13 source . 
  14 source ~/.bashrc
  15 go --version
  16 /usr/lib/go1.11.13/go/bin/go --version
  17 /usr/lib/go1.11.13/go/bin/go version
  18 go version
  19 nano ~/.bashrc
  20 source ~/.bashrc
  21 go version
  22 echo $PATH
  23 nano ~/.bashrc
  24 exit
  25 go version
  26 which go
  27 go help buildmode
  28 echo $PATH
  29 cat /root/.bashrc
  30 export PATH="$PATH:/usr/lib64/go1.11.13/go/bin/"
  31 go help buildmode
  32 go version
  33 echo $PATH
  34 go version
  35 removepkg gcc-go-5.5.0-i586-1_slack14.2
  36 go version
  37 echo $PATH
  38 nano ~/.bashrc
  39 source ~/.bashrc
  40 go version
  41 cat ~/.bashrc
  42 # install docker proxy
  43 cd /tmp
  44 wget https://slackbuilds.org/slackbuilds/14.2/system/docker-proxy.tar.gz
  45 tar xvzf docker-proxy.tar.gz
  46 cd docker-proxy
  47 wget https://github.com/docker/libnetwork/archive/2cfbf9b/libnetwork-2cfbf9b1f98162a55829a21cc603c76072a75382.tar.gz
  48 ./docker-proxy.SlackBuild 
  49 installpkg/tmp/docker-proxy-20181207_2cfbf9b-i586-1_SBo.tgz
  50 # install tini
  51 cd /tmp
  52 wget https://slackbuilds.org/slackbuilds/14.2/system/tini.tar.gz
  53 tar xvzf tini.tar.gz 
  54 cd tini
  55 wget https://github.com/krallin/tini/archive/v0.18.0/tini-0.18.0.tar.gz
  56 ./tini.SlackBuild 
  57 installpkg/tmp/tini-0.18.0-i586-1_SBo.tgz
  58 # install libseccomp
  59 cd /tmp
  60 wget https://slackbuilds.org/slackbuilds/14.2/libraries/libseccomp.tar.gz
  61 tar xvzf libseccomp.tar.gz
  62 cd libseccomp
  63 wget https://github.com/seccomp/libseccomp/archive/v2.4.2/libseccomp-2.4.2.tar.gz
  64 ./libseccomp.SlackBuild 
  65 installpkg/tmp/libseccomp-2.4.2-i586-1_SBo.tgz
  66 # install runc
  67 cd /tmp
  68 wget https://slackbuilds.org/slackbuilds/14.2/system/runc.tar.gz
  69 tar xvzf runc.tar.gz 
  70 cd runc
  71 wget https://github.com/opencontainers/runc/archive/8084f76/runc-8084f7611e4677174c8dbeb17152f3390fa41952.tar.gz
  72 ./runc.SlackBuild
  73 installpkg /tmp/runc-1.0.0_rc6_8084f76-i586-1_SBo.tgz
  74 # install containerd
  75 cd /tmp
  76 wget https://slackbuilds.org/slackbuilds/14.2/system/containerd.tar.gz
  77 tar xvzf containerd.tar.gz
  78 cd containerd
  79 wget https://github.com/containerd/containerd/archive/v1.2.4/containerd-1.2.4.tar.gz
  80 ./containerd.SlackBuild 
  81 installpkg/tmp/containerd-1.2.4-i586-1_SBo.tgz
  82 # install docker
  83 cd /tmp
  84 wget https://slackbuilds.org/slackbuilds/14.2/system/docker.tar.gz
  85 tar xvzf docker.tar.gz
  86 cd docker 
  87 wget https://github.com/docker/docker-ce/archive/v18.09.2/docker-ce-18.09.2.tar.gz
  88 vi docker.SlackBuild 
  89 # change to docker-linux-386
  90 ./docker.SlackBuild
  91 installpkg /tmp/docker-18.09.2-i586-1_SBo.tgz
  92 cd /etc/rc.d
  93 sh rc.docker status
  94 sh rc.docker start
  95 groupadd -r -g 281 docker
  96 usermod -a -G docker vitor
Docker + cherrypy
Setup environment
Ubuntu Dockerfile
   1 FROM ubuntu:20.04
   2 RUN apt update
   3 RUN apt-get install -y curl sudo wget python net-tools vim
   4 RUN mkdir /app
   5 RUN cd /app && curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
   6 RUN cd app/ && python get-pip.py && pip install cherrypy
   7 RUN echo "#!/bin/sh\n python /app/cherry.py" > /start.sh
   8 EXPOSE 80 22 8080 8081
   9 CMD ["sh","/start.sh"]
Alpine Dockerfile
target/cherry.py
Commands to run container
   1 docker build -t env-docker-cherry-image . 
   2 # run container and map docker internal port 8081 to external port 8081
   3 docker run -p 8081:8081 -d -it --rm --name env-docker-cherry-container --mount type=bind,source="$(pwd)"/target,target=/app env-docker-cherry-image
   4 docker ps
   5 # invoke external port 8081 
   6 curl http://localhost:8081/
   7 # change code in target ...
   8 vi target/cherry.py # inside Root class
   9 #    @cherrypy.expose
  10 #    def test(self):
  11 #        return "test hey!".encode('utf8')
  12 # invoke external port 8081 to check the modification made
  13 curl http://localhost:8081/test
  14 #### create net between two containers
  15 docker network create testnet
  16 docker network ls
  17 docker network connect testnet env-docker-cherry-container
  18 docker run -p 8082:8081 -d -it --rm --name env-docker-cherry-container-2 --network testnet --mount type=bind,source="$(pwd)"/target,target=/app env-docker-cherry-image 
  19 docker ps
  20 docker exec -it env-docker-cherry-container-2 ash
  21 # ping env-docker-cherry-container-2
  22 # ping env-docker-cherry-container
  23 docker exec -it env-docker-cherry-container ash
  24 # ping env-docker-cherry-container-2
  25 # ping env-docker-cherry-container
  26 
Setup Proxy for docker daemon
   1 sudo bash
   2 mkdir /etc/systemd/system/docker.service.d
   3 cd  /etc/systemd/system/docker.service.d
   4 nano http-proxy.conf
   5 [Service]
   6 Environment="HTTP_PROXY=http://192.168.22.214:3128"
   7 Environment="HTTPS_PROXY=http://192.168.22.214:3128"
   8 systemctl daemon-reload
   9 systemctl restart docker
  10 
  11 # settings also in ~/.docker/config.json
  12 {
  13 "proxies":
  14  {
  15    "default":
  16    {
  17      "httpProxy": "http://192.168.42.108:3128",
  18      "httpsProxy": "http://192.168.42.108:3128",
  19      "noProxy": "127.0.0.0/8"
  20    }
  21  }
  22 }
Install from binaries in Slackware 15.0
Build image from scratch - Slackware64 15.0 - rootfs
Dockerfile
Steps
   1 mkdir scratch-test
   2 cd scratch-test/
   3 touch Dockerfile
   4 mkdir -p usr/bin/
   5 mkdir lib64
   6 mkdir bin
   7 cp /usr/bin/ls usr/bin/
   8 cp /usr/bin/cat usr/bin/
   9 cp /usr/bin/echo usr/bin/
  10 cp /usr/bin/tail usr/bin/
  11 cp /usr/bin/uname usr/bin/
  12 cp /bin/sh bin/
  13 # to check dependencies use ldd
  14 cp /lib64/libcap.so.2 lib64/
  15 cp /lib64/libc.so.6 lib64/
  16 cp /lib64/libtinfo.so.6 lib64/
  17 cp /lib64/libdl.so.2 lib64/
  18 cp /lib64/ld-linux-x86-64.so.2 lib64/
  19 # build image and run container
  20 docker build -t scratch-test-image .
  21 docker run --rm --name scratch-test-container scratch-test-image
  22 #####
  23 docker build -t scratch-test-image .
  24 docker run -d --rm --name scratch-test-container  scratch-test-image
  25 docker ps 
  26 docker exec -it scratch-test-container sh 
  27 # export container filesystem
  28 docker container export scratch-test-container -o scratch-test.tar
  29 tar tvf scratch-test.tar.gz 
Static binaries in Slackware64
/etc/rc.d/rc.docker
   1 #!/bin/sh
   2 PATH=$PATH:/usr/sbin
   3 
   4 docker_start() {
   5   /usr/bin/dockerd --raw-logs > /var/log/dockerd.log 2>&1 &
   6 }
   7 
   8 docker_stop() {
   9   killall dockerd
  10 }
  11 
  12 docker_restart() {
  13   docker_stop
  14   docker_start
  15 }
  16 
  17 case "$1" in
  18 'start')
  19   docker_start
  20   ;;
  21 'stop')
  22   docker_stop
  23   ;;
  24 'restart')
  25   docker_restart
  26   ;;
  27 *)
  28   echo "usage $0 start|stop|restart"
  29 esac
