Skip to content

Instantly share code, notes, and snippets.

@kvzhuang
Last active September 17, 2018 12:12
Show Gist options
  • Save kvzhuang/8233907 to your computer and use it in GitHub Desktop.
Save kvzhuang/8233907 to your computer and use it in GitHub Desktop.
My Dockerfile, initial shell script and run shell script.
# DOCKER-VERSION 0.3.4
FROM ubuntu
MAINTAINER Kevin Zhuang <[email protected]>
#RUN echo "This is a ubuntu Dockerfile."
#replace source.list with http://repogen.simplylinux.ch/
RUN echo "deb http://02.archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse" > /etc/apt/sources.list
RUN apt-get update
#For docker. issue
RUN dpkg-divert --local --rename --add /sbin/initctl;ln -s /bin/true /sbin/initctl
#add-apt-repository ppa:ondrej/php5-oldstable is for php old stable version
RUN apt-get install -y git wget dnsmasq mysql-server python-software-properties;add-apt-repository ppa:ondrej/php5-oldstable
RUN mkdir /root/.ssh
#you may get you ssh key or generate later
RUN chmod 700 /root/.ssh/id_rsa;chmod 700 /root/.ssh/id_rsa.pub
#For autotest, I make StrictHostKeyChecking to no, if you have sercurty concern, please do NOT add this.
RUN touch /root/.ssh/config;echo "Host *\n StrictHostKeyChecking no\n UserKnownHostsFile=/dev/null" > /root/.ssh/config
#make git repo folder, change GIT_LOCATION
RUN mkdir -p /home/m/share/htdosc;cd /home/m/share/htdosc;git clone GIT_LOCATION;cd /
RUN ln -s /home/m/share/htdosc/GIT_LOCATION/init.sh /init.sh;ln -s /home/m/share/htdosc/GIT_LOCATION/run.sh /run.sh
#Append dnsmasq conf
RUN echo "listen-address=127.0.0.1\nconf-dir=/etc/dnsmasq.d\naddress=/your.domain.com/127.0.0.1\nresolv-file=/etc/resolv.dnsmasq.conf">>/etc/dnsmasq.conf
#Append common dns server to dnsmasq
RUN echo "nameserver 8.8.8.8\nnameserver 8.8.4.4">/etc/resolv.dnsmasq.conf
#Append to run init shell script and run.sh, you can change for your script.
RUN echo ". /init.sh\n./run.sh\n . /root/.bashrc">> /etc/bash.bashrc
#if your want run this container and quit, use next script.
#RUN echo ". /init.sh\n./run.sh\n . /root/.bashrc\nexit">> /etc/bash.bashrc
#Change timezon setting
RUN echo "Asia/Taipei">/etc/timezone
#Build(or rebuild) in next shell script.
#sudo docker rmi kvzhuang/ubuntu_env
#sudo docker build -t="kvzhuang/ubuntu_env" .
#sudo docker run -i -t -dns='localhost' kvzhuang/ubuntu_env /bin/bash
#! /bin/bash
service dnsmasq restart &
sleep 5
apt-get update
#this is my packages, you can change your own.
apt-get install -y vim
apt-get install -y apache2
apt-get install -y php5
apt-get install -y memcached
apt-get install -y curl
apt-get install -y php5-curl
apt-get install -y php5-mysql
apt-get install -y php5-memcached
apt-get install -y pdo-mysql
apt-get install -y php-pear
apt-get install -y expect
apt-get install -y scp
#this is for PHPUnit.
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit
locale-gen en_US en_US.UTF-8 zh_TW.UTF-8
mkdir -p /home/m/share/htdosc/log/apache
#this is my repo apache setting, I linked to apache sites-available
ln -s /home/m/share/htdosc/GIT_LOCATION/apache/your_own.conf /etc/apache2/sites-available/your_own.conf
ln -s /etc/apache2/sites-available/your_own.conf /etc/apache2/sites-enabled/your_own.conf
#remove default apache config and php files for timezone setting, this is optional.
rm /etc/apache2/sites-enabled/000-default
rm /etc/php5/apache2/php.ini
cp /home/m/share/htdosc/GIT_LOCATION/php/php.ini /etc/php5/apache2/
#I use apache2 rewrite.
a2enmod rewrite
#git pull for newest call
cd /home/m/share/htdosc/GIT_LOCATION;git -f pull;cd /
#!/bin/bash
export TZ="/usr/share/zoneinfo/Asia/Taipei"
mysqld > /dev/null 2>&1 &
sleep 5
service memcached restart &
sleep 5
service apache2 restart &
sleep 5
service dnsmasq restart &
sleep 5
#You may update your database schema or data.
mysql -uroot test</home/m/share/htdosc/GIT_LOCATION/init.sql
#run your PHPUnit config.
phpunit --log-junit results.xml -c /home/m/share/htdosc/GIT_LOCATION/phpunit.xml
#this run expect to upload result file to outside server.
expect -c "
spawn scp results.xml YOUR_REPORT_LOCATION
expect {
\"*assword\" {set timeout 300; send \"your_password\r\";}
\"yes/no\" {send \"yes\r\"; exp_continue;}
}
expect eof"
@scrollbili
Copy link

I don't undestand, please could you explain to my how to execute a script in the dockerfile ?Please :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment