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:
- curl -fsSL https://get.docker.com > docker-install.sh
- change line 412, to use pgp.mit.edu as it fails to get keys from p80.pool.sks-keyservers
- 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:
- FROM ubuntu
- MAINTAINER thinakar thinakar@gmail.com
- RUN apt-get -y install apache2
- RUN echo "Hello, Apache on Ubuntu Docker" > /var/www/html/index.html
- EXPOSE 80
- 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....
- 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
- ADD oracle/instantclient-basic-linux.x64-12.1.0.2.0.zip /tmp/instantclient-basic-linux.x64-12.1.0.2.0.zip
- ADD oracle/instantclient-sdk-linux.x64-12.1.0.2.0.zip /tmp/instantclient-sdk-linux.x64-12.1.0.2.0.zip
- ADD oracle/instantclient-sqlplus-linux.x64-12.1.0.2.0.zip /tmp/instantclient-sqlplus-linux.x64-12.1.0.2.0.zip
- RUN apt-get install -y unzip
- RUN unzip /tmp/instantclient-basic-linux.x64-12.1.0.2.0.zip -d /usr/local/
- RUN unzip /tmp/instantclient-sdk-linux.x64-12.1.0.2.0.zip -d /usr/local/
- RUN unzip /tmp/instantclient-sqlplus-linux.x64-12.1.0.2.0.zip -d /usr/local/
- RUN ln -s /usr/local/instantclient_12_1 /usr/local/instantclient
- RUN ln -s /usr/local/instantclient/libclntsh.so.12.1 /usr/local/instantclient/libclntsh.so
- RUN ln -s /usr/local/instantclient/sqlplus /usr/bin/sqlplus
- RUN apt-get install libaio-dev -y
- RUN apt-get clean -y
- ADD apache2 /etc/apache2
- RUN a2enmod ldap authnz_ldap headers
- RUN a2enmod ldap authnz_ldap
- # sudo a2ensite <SITE_NAME>
- RUN a2enmod authz_core
- RUN a2enmod include alias
- RUN a2enmod negotiation
- RUN a2enmod headers
- RUN a2enmod cgi
- RUN chmod -R 775 ~/.cpanm
- COPY environment /etc
- RUN mkdir -p /usr/local/instantclient/network/admin
- COPY tnsnames.ora /usr/local/instantclient/network/admin
- # WORKDIR cgi-bin
- EXPOSE 22 80
- CMD ["/usr/bin/supervisord"]
- Get link
- X
- Other Apps