Docker Apache: inside virtualBox 5, ubuntu 14




Tips/Gotchas: 
add yourself to group docker to run docker command without "sudo".
sudo usermod -aG docker tperiasa

get docker:
curl -fsSL https://get.docker.com | sh
Does not work.
Hence get the shell script as:
    1. curl -fsSL https://get.docker.com > docker-install.sh
    2. change line 412, to use pgp.mit.edu as it fails to get keys from p80.pool.sks-keyservers
    3. Run docker-install.sh
412c412,413
< $sh_c "apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D"
---
> $sh_c "apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D"

Dockerfile:

  1. FROM ubuntu  
  2. MAINTAINER thinakar thinakar@gmail.com  
  3. RUN apt-get -y install apache2  
  4. RUN echo "Hello, Apache on Ubuntu Docker" > /var/www/html/index.html  
  5. EXPOSE 80  
  6. CMD /usr/sbin/apache2ctl -D FOREGROUND  

Build:
docker build -t docker-perlapp  ubuntu/apache
- "-t" tag option...

Run:

docker run -p 8080:80 -t -i thinakar/ubuntu-apache
- map the localhost port 8080 to container 80
- "-t" option ==> tty mode, with console output
- "-i" image name...

Access:
tperiasa@ub-14:~$ curl http://localhost:8080
Hello, Apache on Ubuntu Docker
tperiasa@ub-14:~$

process list and kill:
tperiasa@ub-14:~$ docker ps
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                  NAMES
1f1b77bdd777        thinakar/ubuntu-apache   "/bin/sh -c '/usr/sbi"   3 minutes ago       Up 3 minutes        0.0.0.0:8080->80/tcp   mad_brown
tperiasa@ub-14:~$ docker kill 1f1b77bdd777
1f1b77bdd777
tperiasa@ub-14:~$

Attach to container:

tperiasa@ub-14:~/mydockerbuild$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                        NAMES
61c4334ce81a        ubuntu-perlapp      "/usr/bin/supervisord"   18 minutes ago      Up 18 minutes       0.0.0.0:2200->22/tcp, 0.0.0.0:8080->80/tcp   big_ritchie
tperiasa@ub-14:~/mydockerbuild$
tperiasa@ub-14:~/mydockerbuild$
tperiasa@ub-14:~/mydockerbuild$ docker exec -it 61c4334ce81a bash
root@61c4334ce81a:/# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.8  52144 16856 ?        Ss+  00:27   0:00 /usr/bin/python /usr/bin/supervisord
root         8  0.0  0.2  61384  5268 ?        S    00:27   0:00 /usr/sbin/sshd -D
root         9  0.0  0.2  71312  4832 ?        S    00:27   0:00 /usr/sbin/apache2 -DFOREGROUND
www-data    10  0.0  0.3 426076  6568 ?        Sl   00:27   0:00 /usr/sbin/apache2 -DFOREGROUND
www-data    11  0.0  0.3 360476  6160 ?        Sl   00:27   0:00 /usr/sbin/apache2 -DFOREGROUND
root       133  1.0  0.1  18172  3108 ?        Ss   00:46   0:00 bash
root       147  0.0  0.1  15572  2112 ?        R+   00:46   0:00 ps aux
root@61c4334ce81a:/#


Dockerfile:  PerlApp with Apache config
FROM ubuntu
MAINTAINER thinakar thinakar@gmail.com
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get install -y openssh-server apache2 supervisor
RUN apt-get -y install cpanminus
RUN apt-get -y install make
RUN apt-get -y install libwww-perl
RUN apt-get -y install libexpat1-dev
#  doesnot work: RUN cachebuster=d437fe55 curl -L http://cpanmin.us | perl - App::cpanminus
RUN cpanm Carton
RUN cpanm Starman
#      FAILED: Installing the dependencies failed: Module 'HTTP::Parser::XS' is not installed
RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/run/sshd /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# WORKDIR cgi-bin
EXPOSE 22 80
CMD ["/usr/bin/supervisord"]

supervisord.conf
[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D
[program:apache2]
command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"


Push to Docker Hub:

tperiasa@ub-14:~/mydockerbuild/ubuntu/perlapp$ docker login
Username (thinakar):
Password:
WARNING: login credentials saved in /home/tperiasa/.docker/config.json
Login Succeeded

tperiasa@ub-14:~/mydockerbuild/ubuntu/perlapp$ docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
ubuntu-perlapp           latest              3cc9b337bda1        12 minutes ago      666.5 MB
....
tperiasa@ub-14:~/mydockerbuild/ubuntu/perlapp$ docker tag 3cc9b337bda1 thinakar/ubuntu-perlapp:latest
tperiasa@ub-14:~/mydockerbuild/ubuntu/perlapp$ docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
thinakar/ubuntu-perlapp   latest              3cc9b337bda1        15 minutes ago      666.5 MB
ubuntu-perlapp            latest              3cc9b337bda1      15 minutes ago      666.5 MB


tperiasa@ub-14:~/mydockerbuild/ubuntu/perlapp$ docker push thinakar/ubuntu-perlapp
The push refers to a repository [docker.io/thinakar/ubuntu-perlapp]
ba0207798a83: Pushed
.......
a591b287e755: Pushed
latest: digest: sha256:7b24a83e4462b63b0bf6368d4800790343a44163ba7bf8213f3614c07d39aad7 size: 22283
tperiasa@ub-14:~/mydockerbuild/ubuntu/perlapp$ docker images


Docker file for perl applications....


  1. FROM ubuntu  
  2. MAINTAINER thinakar thinakar@gmail.com  
  3. RUN apt-get update -y  
  4. RUN apt-get upgrade -y  
  5. RUN apt-get install -y openssh-server apache2 supervisor  
  6. RUN apt-get -y install cpanminus  
  7. RUN apt-get -y install make  
  8. RUN apt-get -y install libwww-perl  
  9. RUN apt-get -y install libexpat1-dev  
  10. #  doesnot work: RUN cachebuster=d437fe55 curl -L http://cpanmin.us | perl - App::cpanminus  
  11. RUN cpanm Carton  
  12. RUN cpanm Starman  
  13. #      FAILED: Installing the dependencies failed: Module 'HTTP::Parser::XS' is not installed  
  14. RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/run/sshd /var/log/supervisor  
  15. COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf  
  16.   
  17.   
  18. ADD oracle/instantclient-basic-linux.x64-12.1.0.2.0.zip    /tmp/instantclient-basic-linux.x64-12.1.0.2.0.zip  
  19. ADD oracle/instantclient-sdk-linux.x64-12.1.0.2.0.zip      /tmp/instantclient-sdk-linux.x64-12.1.0.2.0.zip  
  20. ADD oracle/instantclient-sqlplus-linux.x64-12.1.0.2.0.zip  /tmp/instantclient-sqlplus-linux.x64-12.1.0.2.0.zip  
  21.   
  22.   
  23. RUN apt-get install -y unzip  
  24.   
  25.   
  26. RUN unzip /tmp/instantclient-basic-linux.x64-12.1.0.2.0.zip    -d /usr/local/  
  27. RUN unzip /tmp/instantclient-sdk-linux.x64-12.1.0.2.0.zip      -d /usr/local/  
  28. RUN unzip /tmp/instantclient-sqlplus-linux.x64-12.1.0.2.0.zip  -d /usr/local/  
  29.   
  30.   
  31. RUN ln -s /usr/local/instantclient_12_1 /usr/local/instantclient  
  32. RUN ln -s /usr/local/instantclient/libclntsh.so.12.1 /usr/local/instantclient/libclntsh.so  
  33. RUN ln -s /usr/local/instantclient/sqlplus /usr/bin/sqlplus  
  34.   
  35.   
  36. RUN apt-get install libaio-dev -y  
  37. RUN apt-get clean -y  
  38.   
  39.   
  40. ADD apache2 /etc/apache2  
  41. RUN a2enmod ldap authnz_ldap   headers  
  42. RUN a2enmod ldap authnz_ldap  
  43. # sudo a2ensite <SITE_NAME>  
  44. RUN a2enmod authz_core  
  45. RUN a2enmod include alias  
  46. RUN a2enmod negotiation  
  47. RUN a2enmod headers  
  48. RUN a2enmod cgi  
  49. RUN chmod -R 775 ~/.cpanm  
  50.   
  51.   
  52. COPY environment /etc  
  53. RUN  mkdir -p /usr/local/instantclient/network/admin  
  54. COPY tnsnames.ora /usr/local/instantclient/network/admin  
  55.   
  56.   
  57. # WORKDIR cgi-bin  
  58. EXPOSE 22 80  
  59. CMD ["/usr/bin/supervisord"]  

Popular Posts