-
Notifications
You must be signed in to change notification settings - Fork 3
Home
Jason Greathouse edited this page Jul 10, 2015
·
7 revisions
cd ~/docker
curl -sSL https://get.docker.io/ubuntu/ | sudo sh
Add your user to docker group:
sudo usermod -G docker -a vagrant
Log out and log back in.
jgreat/osx-docker
Install file: TODO Install vagrant/ubuntu-vm
docker run -d --name wp-mysql \
-e MYSQL_DATABASE=wp \
-e MYSQL_USER=wpuser \
-e MYSQL_PASSWORD=wppass \
-e MYSQL_ROOT_PASSWORD=rootpw \
-p 172.17.42.1:3306:3306 \
-v /data/mysql:/var/lib/mysql \
mysql
docker ps
docker inspect wp-mysql
docker stop wp-mysql
docker ps -a
docker start wp-mysql
docker logs -f wp-mysql
docker pull ubuntu:14.04
mkdir -p ~/docker/wp
cd ~/docker/wp
wget -O wordpress.tar.gz https://wordpress.org/latest.tar.gz
tar xvzf wordpress.tar.gz
cd wordpress
cp wp-config-sample.php wp-config.php
vi wp-config.php
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', getenv('MYSQL_DB'));
/** MySQL database username */
define('DB_USER', getenv('MYSQL_USER'));
/** MySQL database password */
define('DB_PASSWORD', getenv('MYSQL_PWD'));
/** MySQL hostname */
define('DB_HOST', getenv('MYSQL_HOST'));
mkdir -p .docker/apache2/sites-enabled
vi .docker/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@jgreat.me
ServerName jgreat.me
DocumentRoot /var/www/wp/wordpress
<Directory /var/www/wp/wordpress>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog "|/bin/cat"
CustomLog "|/bin/cat" combined
LogLevel warn
</VirtualHost>
mkdir -p .docker/bin
vi .docker/bin/entry.sh
#!/bin/bash
# This script is used when linking dockers for development.
# Docker doesn't have a great way to set runtime environment variables, if
# linking dockers so...
set -e
if [ ! -z "${MYSQL_PORT_3306_TCP_ADDR}" ]; then
export MYSQL_HOST=$MYSQL_PORT_3306_TCP_ADDR
fi
if [ ! -z "${MYSQL_ENV_MYSQL_DATABASE}" ]; then
export MYSQL_DB=$MYSQL_ENV_MYSQL_DATABASE
fi
if [ ! -z "${MYSQL_ENV_MYSQL_USER}" ]; then
export MYSQL_USER=$MYSQL_ENV_MYSQL_USER
fi
if [ ! -z "${MYSQL_ENV_MYSQL_PASSWORD}" ]; then
export MYSQL_PWD=$MYSQL_ENV_MYSQL_PASSWORD
fi
# Execute the commands passed to this script
exec "$@"
chmod +x .docker/bin/entry.sh
vi .docker/bin/start-app.sh
#!/bin/bash
apachectl -DFOREGROUND
chmod +x .docker/bin/start-app.sh
cd ~/docker/wp
vi Dockerfile
#Wordpress Apache Docker Image
FROM ubuntu:14.04
MAINTAINER Jason Greathouse
#install apache, php and mysql client
RUN apt-get update && \
apt-get install -y php5 libapache2-mod-php5 php5-mysql php5-cli mysql-client
#clean up apt files
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/*
#add wordpress files
ADD . /var/www/wp
#add apache vhost config (overwrite default)
ADD .docker/apache2/sites-enabled/000-default.conf /etc/apache2/sites-enabled/000-default.conf
#add entrypoint and start up scripts
ADD .docker/bin /usr/local/bin
#Change the working directory to the app root
WORKDIR /var/www/wp
#entrypoint script to set env vars when linking containers for dev
ENTRYPOINT ["/usr/local/bin/entry.sh"]
#Default command to run on start up
#/usr/sbin/apachectl -DFOREGROUND
CMD ["/usr/local/bin/start-app.sh"]
docker build -t wp .
docker run -it --rm \
--link wp-mysql:mysql \
--publish 80:80 \
wp
Varies on OS/VM.
vagrant: vagrant ssh ip addr
docker tag wp jgreat/wp
docker tag jgreat/wp jgreat/wp:1.0.5
docker push jgreat/wp
This will live behind a local proxy.
docker run -d \
--publish 127.0.0.1:5000:80 \
-e MYSQL_HOST=mysql.example.com \
-e MYSQL_DB=wp-prd \
-e MYSQL_USER=wp-prd \
-e MYSQL_PWD=t9hutiZygiukngnwB+m0x \
jgreat/wp:1.0.5
docker stop wp-mysql
docker rm -v wp-mysql
docker rmi mysql
Show Images
docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
jgreat/wp 1.0.5 b11f325ababc 28 hours ago 334.5 MB
jgreat/wp latest b11f325ababc 28 hours ago 334.5 MB
wp latest b11f325ababc 28 hours ago 334.5 MB
ubuntu 14.04 c4ff7513909d 2 weeks ago 213 MB
ubuntu latest c4ff7513909d 2 weeks ago 213 MB
Delete all unused images
docker images | awk '{print $3}'| xargs docker rmi
Deleted: a9f968d6c5e283176ddf7cdc41398612c0013dae6d6293e61ece13912985d6df
Deleted: 00f534926ee33d9c3b46157de9de081a6f0ebf9fafabb679d5f4fa0ea4c7cb46
...
Deleted: 8ed955b5caa1af67a1d08a88e19c1c9b72967a800ed6cc62285f2a97ee4c292d
Deleted: 70a06ea1c45a067981ace6f8c58aaabe6c10c55c5152039bdd7070574bdd42e6