Skip to content

Instantly share code, notes, and snippets.

@garretttaco
Last active August 29, 2015 14:27
Show Gist options
  • Save garretttaco/6aa476cdde3dfd5dd8b3 to your computer and use it in GitHub Desktop.
Save garretttaco/6aa476cdde3dfd5dd8b3 to your computer and use it in GitHub Desktop.
Docker file

##Get Docker on Mac OSX:

###Step 1.

https://docs.docker.com/installation/mac/

install docker toolbox.

skip the docker quick start step and go to the "from your shell” section on the run of docker-machine env default put the export results into the .bashrc file

###Step 2. search for a image to use on https://hub.docker.com/ i.e. php-apache or create a Dockerfile

example file:

FROM php:5.5-apache

COPY . /var/www/html/

#Install modules
RUN apt-get update && apt-get install -y \
	libfreetype6-dev \
	libjpeg62-turbo-dev \
	libmcrypt-dev \
	libpng12-dev \
	php5-dev \
	php-pear \
	vim \
&& docker-php-ext-install iconv mcrypt mbstring \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd \
&& a2enmod rewrite \
&& pecl install redis \
&& echo "extension=redis.so" > /usr/local/etc/php/conf.d/redis.ini \
&& pecl install xdebug \
&& echo "extension=/usr/local/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so" > /usr/local/etc/php/conf.d/xdebug.ini

CMD ["apache2-foreground”]

###step 3:

run $ docker build -t garrett-php .

then run docker images

see if it installed the image

then run

docker run -p 80:80 -d -v /Users/Garrett/NetbeansProjects:/var/www/html --name web garrett-php

if you run docker ps -a

you should see that is is running and hasn’t exited

running this will allow you to go inside of the container

docker exec -it <containerIdOrName> bash

container name can be whatever is supplied after the --name so 'web' would be exceptable

feel free to add dependancies from there. i.e. the nano editor...

###.bash_profile

################### DOCKER

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/Garrett/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"


dls() {
  docker ps
}

dll() {
  docker ps -a
}

dim() {
   docker images
}

# docker stop
dsto() {
  if [[ $# -eq 0 ]]
    then
      echo "Which container? Provide 1 argument."
      return 0
  fi
  docker stop $1
}

# docker start
dsta() {
  if [[ $# -eq 0 ]]
    then
      echo "Which container? Provide 1 argument."
      return 0
  fi
  docker start $1
}

# docker remove
drm() {
  if [[ $# -eq 0 ]]
    then
      echo "Which container? Provide 1 argument."
      return 0
  fi
  docker rm $1
}

# docker stop all running
dsar() {
    if [[ $# -eq 0 ]]
      then
        docker ps | tail -n +2 |cut -d ' ' -f 1 | xargs docker stop
    else
        dsto $1;
    fi
}
alias dstop='dsar'

# docker remove all stopped
dras() {
    docker ps -a | tail -n +2 | grep Exited | cut -d ' ' -f 1 | xargs docker rm
}

# docker kill all
docker-killall() {
    dsar
    dras
}
alias dka='docker-killall'


# Docker get an ext ip
dip() {
  if [[ $# -eq 0 ]]
    then
      echo "Which container? Provide 1 argument."
      return 0
  fi
   docker inspect --format='{{.NetworkSettings.IPAddress}}' $1
}

drun() {
  if [[ $# -eq 0 ]]
    then
      echo "Which container? Provide 1 argument."
      return 0
  fi

  case "$1" in

    'web' )
        docker run -d \
        --name web \
        -p 80:80 \
        -e APP=web \
        -v /Users/Garrett/NetBeansProjects:/var/www/html \
        -t garrett-php \
        apache2-foreground
        ;;

  esac

}


docker-enter() {
  if [[ $# -eq 0 ]]
    then
      echo "Which container? Provide 1 argument."
      return 0
  fi

  docker exec -ti $1 bash
}
alias de='docker-enter'


################### GIT


if [ -f ~/.git-completion.bash ]; then
  . ~/.git-completion.bash
fi


################### OTHER

listening() {
  sudo lsof -i -n -P | grep TCP
}

/etc/apache2/sites-available/000-default.conf in the debian server

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    <Directory /var/www/html>
            Options Indexes FollowSymLinks
            IndexOptions FancyIndexing HTMLTable
            DirectoryIndex index.html index.htm index.php
            Allow from all
            Order Allow,Deny
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    # ErrorLog ${APACHE_LOG_DIR}/error.log
    # CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    # Include conf-available/serve-cgi-bin.conf
</VirtualHost>

run a2ensite 000-default this will make a symlink from the sites available to the sites enabled

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