-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docker tutorials: docker, docker-compose, ansible
- Loading branch information
Showing
14 changed files
with
283 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
cask_args appdir: '/Applications' | ||
cask 'virtualbox' | ||
cask 'virtualbox-extension-pack' | ||
cask 'vagrant' | ||
cask 'docker-toolbox' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Docker Command vs Ansible Playbook Tutorial | ||
|
||
## Mac OS X | ||
|
||
```bash | ||
##### Install | ||
./helper-mac-install.sh | ||
##### Start a VM if needed | ||
docker-machine create --driver 'virtualbox' docker-ansible | ||
eval $(docker-machine env docker-ansible) | ||
|
||
##### Test Shell Ansible | ||
./docker-wordpress.sh | ||
curl $(docker-machine ip docker-ansible) | ||
##### Cleanup (removes everything on this guest vm) | ||
docker ps -q | xargs docker stop | ||
docker ps -aq | xargs docker rm | ||
|
||
##### Test Docker Ansible | ||
./docker-wordpress-shell.yml | ||
curl $(docker-machine ip docker-ansible) | ||
##### Cleanup (removes everything on this guest vm) | ||
docker ps -q | xargs docker stop | ||
docker ps -aq | xargs docker rm | ||
|
||
##### Test Docker Ansible | ||
./docker-wordpress.yml | ||
curl $(docker-machine ip docker-ansible) | ||
##### Cleanup (removes everything on this guest vm) | ||
docker ps -q | xargs docker stop | ||
docker ps -aq | xargs docker rm | ||
|
||
##### Stop and Remove Guest VM | ||
docker-machine stop docker-ansible | ||
docker-machine rm docker-ansible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env ansible-playbook | ||
--- | ||
- hosts: localhost | ||
gather_facts: no | ||
vars: | ||
docker_volume: db_data | ||
docker_network: ansible_net | ||
db_name: db | ||
wp_name: wordpress | ||
wp_host_port: 8000 | ||
wp_container_port: 80 | ||
tasks: | ||
- name: Create docker volume | ||
shell: docker volume create -d local --name {{ docker_volume }} | ||
- name: Search for docker network | ||
shell: docker network ls | grep -q {{ docker_network }} | ||
register: test_docker_network | ||
ignore_errors: yes | ||
- name: Create docker network | ||
shell: docker network create {{ docker_network }} | ||
when: test_docker_network.rc != 0 | ||
- name: Launch database container | ||
shell: > | ||
docker run -d | ||
-v {{ docker_volume }}:/var/lib/mysql:rw | ||
--network={{ docker_network }} | ||
--network-alias {{ db_name }} | ||
--restart=always | ||
-e MYSQL_ROOT_PASSWORD=wordpress | ||
-e MYSQL_PASSWORD=wordpress | ||
-e MYSQL_USER=wordpress | ||
-e MYSQL_DATABASE=wordpress | ||
--name {{ db_name }} | ||
mysql:5.7 | ||
- name: Launch wordpress container | ||
shell: > | ||
docker run -d | ||
--network={{ docker_network }} | ||
--network-alias {{ wp_name }} | ||
-p "{{ wp_host_port }}:{{ wp_container_port }}" | ||
--restart=always | ||
-e WORDPRESS_DB_HOST="{{ db_name }}:3306" | ||
-e WORDPRESS_DB_PASSWORD=wordpress | ||
--name {{ wp_name }} | ||
wordpress:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/sh | ||
|
||
# create the network if network does not exist | ||
docker network list | grep -q "wordpress_net" || \ | ||
docker network create "wordpress_net" | ||
|
||
# create volumes | ||
docker volume create -d local --name "db_data" | ||
|
||
# start mysql database | ||
docker run -d \ | ||
-v db_data:/var/lib/mysql:rw \ | ||
--network='wordpress_net' \ | ||
--network-alias db \ | ||
--restart=always \ | ||
-e MYSQL_ROOT_PASSWORD='wordpress' \ | ||
-e MYSQL_PASSWORD='wordpress' \ | ||
-e MYSQL_USER='wordpress' \ | ||
-e MYSQL_DATABASE='wordpress' \ | ||
--name db mysql:5.7 | ||
|
||
# start wordpress application | ||
docker run -d \ | ||
--network=wordpress_net \ | ||
--network-alias wordpress \ | ||
-p "8080:80" \ | ||
--restart=always \ | ||
-e WORDPRESS_DB_HOST="db:3306" \ | ||
-e WORDPRESS_DB_PASSWORD='wordpress' \ | ||
--name wordpress wordpress:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env ansible-playbook | ||
--- | ||
- hosts: localhost | ||
gather_facts: no | ||
vars: | ||
docker_volume: db_data | ||
docker_network: ansible_net | ||
db_name: db | ||
wp_name: wordpress | ||
wp_host_port: 8000 | ||
wp_container_port: 80 | ||
tasks: | ||
- name: "Create a Volume" | ||
docker_volume: | ||
name: "{{ docker_volume }}" | ||
# ansible 2.2 only | ||
- name: "Create a network" | ||
docker_network: | ||
name: "{{ docker_network }}" | ||
- name: "Launch database container" | ||
docker_container: | ||
name: "{{ db_name }}" | ||
image: mysql:5.7 | ||
volumes: | ||
- "{{ docker_volume }}:/var/lib/mysql:rw" | ||
restart: true | ||
networks: | ||
- name: "{{ docker_network }}" | ||
alias: | ||
- "{{ db_name }}" | ||
env: | ||
MYSQL_ROOT_PASSWORD: wordpress | ||
MYSQL_DATABASE: wordpress | ||
MYSQL_USER: wordpress | ||
MYSQL_PASSWORD: wordpress | ||
- name: "Launch wordpress container" | ||
docker_container: | ||
name: "{{ wp_name }}" | ||
image: wordpress:latest | ||
ports: | ||
- "{{ wp_host_port }}:{{ wp_container_port }}" | ||
restart: true | ||
networks: | ||
- name: "{{ docker_network }}" | ||
alias: | ||
- "{{ wp_name }}" | ||
env: | ||
WORDPRESS_DB_HOST: "{{ db_name }}:3306" | ||
WORDPRESS_DB_PASSWORD: wordpress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
# only run on Mac OS X | ||
[ $(uname -s) = "Darwin" ] || { echo 'Only runs on Mac OS X!!!' ; exit 1 ; } | ||
# Install Homebrew | ||
which -s brew || /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | ||
|
||
brew bundle --verbose | ||
|
||
pip install -r requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ansible | ||
docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
cask_args appdir: '/Applications' | ||
cask 'virtualbox' | ||
cask 'virtualbox-extension-pack' | ||
cask 'vagrant' | ||
cask 'docker-toolbox' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Docker Command vs Ansible Playbook Tutorial | ||
|
||
## Mac OS X | ||
|
||
These are the commands you can use to startup and cleanup each test | ||
|
||
```bash | ||
##### Install | ||
./helper-mac-install.sh | ||
##### Start a VM if needed | ||
docker-machine create --driver 'virtualbox' docker-compose-tutorial | ||
eval $(docker-machine env docker-compose-tutorial) | ||
|
||
##### Test Shell Ansible | ||
./docker-wordpress.sh | ||
curl $(docker-machine ip docker-compose-tutorial):8080 | ||
##### Cleanup (removes everything on this guest vm) | ||
docker ps -q | xargs docker stop | ||
docker ps -aq | xargs docker rm | ||
|
||
##### Test Docker Compose | ||
pushd compose_static | ||
docker-compose up -d | ||
curl $(docker-machine ip docker-compose-tutorial):8000 | ||
##### Cleanup (removes everything on this guest vm) | ||
docker-compose stop | ||
docker-compose rm | ||
popd | ||
|
||
##### Test Docker Compose | ||
pushd compose_w_envars | ||
docker-compose up -d | ||
curl $(docker-machine ip docker-compose-tutorial):8000 | ||
##### Cleanup (removes everything on this guest vm) | ||
docker-compose stop | ||
docker-compose rm | ||
popd | ||
|
||
##### Stop and Remove Guest VM | ||
docker-machine stop docker-compose-tutorial | ||
docker-machine rm docker-compose-tutorial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
version: '2' | ||
services: | ||
db: | ||
image: mysql:5.7 | ||
volumes: | ||
- db_data:/var/lib/mysql | ||
restart: always | ||
environment: | ||
MYSQL_ROOT_PASSWORD: wordpress | ||
MYSQL_DATABASE: wordpress | ||
MYSQL_USER: wordpress | ||
MYSQL_PASSWORD: wordpress | ||
wordpress: | ||
depends_on: | ||
- db | ||
image: wordpress:latest | ||
ports: | ||
- "8000:80" | ||
restart: always | ||
environment: | ||
WORDPRESS_DB_HOST: db:3306 | ||
WORDPRESS_DB_USER: wordpress | ||
WORDPRESS_DB_PASSWORD: wordpress | ||
volumes: | ||
db_data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
WP_HOST_PORT=8000 | ||
WP_CONTAINER_PORT=80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
version: '2' | ||
services: | ||
db: | ||
image: mysql:5.7 | ||
volumes: | ||
- db_data:/var/lib/mysql | ||
restart: always | ||
environment: | ||
MYSQL_ROOT_PASSWORD: wordpress | ||
MYSQL_DATABASE: wordpress | ||
MYSQL_USER: wordpress | ||
MYSQL_PASSWORD: wordpress | ||
wordpress: | ||
depends_on: | ||
- db | ||
image: wordpress:latest | ||
ports: | ||
- "${WP_HOST_PORT}:${WP_CONTAINER_PORT}" | ||
restart: always | ||
environment: | ||
WORDPRESS_DB_HOST: db:3306 | ||
WORDPRESS_DB_USER: wordpress | ||
WORDPRESS_DB_PASSWORD: wordpress | ||
volumes: | ||
db_data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
# only run on Mac OS X | ||
[ $(uname -s) = "Darwin" ] || { echo 'Only runs on Mac OS X!!!' ; exit 1 ; } | ||
# Install Homebrew | ||
which -s brew || /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | ||
|
||
brew bundle --verbose |