Last active
May 10, 2018 06:41
-
-
Save krasnikovdev/f40fde80707c2137ee0157b4032a6c1c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Устанавливаем Docker | |
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D | |
sudo apt-add-repository 'deb https://apt.dockerproject.org/repo ubuntu-xenial main' | |
sudo apt-get update | |
sudo apt-get install -y docker-engine | |
sudo usermod -aG docker $(whoami) | |
Перелогиниваемся. | |
----------------------------------------------------------------------------------- | |
Устанавливаем docker-compose: | |
sudo curl -L https://github.com/docker/compose/releases/download/1.21.1/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose/usr/local/bin/docker-compose | |
Выставляем права: | |
sudo chmod +x /usr/local/bin/docker-compose | |
Проверяем чтобы все работало: | |
docker-compose --version | |
---------------------------------------------------------------------------------- | |
Создаем Docker контейнеры | |
mkdir docker | |
cd docker/ | |
создаем необходимые папки | |
mkdir {app,db,nginx,php-fpm} | |
Создаем конфигурацию | |
nano docker-compose.yml | |
------------------------------------------------------------------------------------ | |
Код контейнера | |
-------------- | |
# Версия docker-compose | |
version: '2' | |
# Список наших сервисов (контейнеров) | |
services: | |
php: | |
container_name: php | |
#Собираем образ по Docker файлу | |
build: ./php-fpm | |
ports: | |
- 9000:9000 | |
#Локальная папка с сайтом:Папка сайта в Docker контейнере | |
volumes: | |
- ./app:/var/www/site | |
#Связь с базой данных | |
links: | |
- db | |
nginx: | |
#Подключаем готовый образ nginx | |
image: nginx:latest | |
ports: | |
- 8080:80 | |
#Импортируем папку с проэктом и конфигурацию nginx | |
volumes: | |
- ./app:/var/www/site/ | |
- ./nginx/app.conf:/etc/nginx/conf.d/default.conf:ro | |
#Связь с php | |
links: | |
- php | |
command: [nginx-debug, '-g', 'daemon off;'] | |
db: | |
image: mysql | |
ports: | |
- 33060:3306 | |
#Настройки бд | |
environment: | |
MYSQL_DATABASE: mydb | |
MYSQL_USER: dev | |
MYSQL_PASSWORD: 123123 | |
MYSQL_ROOT_PASSWORD: 123123 | |
#Импортируем базу данных, что бы она не очищалась при перезапуске сервера | |
volumes: | |
- ./db:/var/lib/mysql | |
----------------------------------------------------------------------- | |
Создаем Dockerfile для сборки php-fpm | |
nano php-fpm/Dockerfile | |
----------------------------------------------------------------------- | |
Код файла Dockerfile | |
-------------------- | |
#исходный образ | |
FROM php:7-fpm | |
#устанавливаем необходимые компоненты | |
RUN apt-get update && apt-get install -y curl zip unzip git vim libpng-dev libmcrypt-dev libreadline-dev | |
№устанавливаем компоненты php | |
RUN docker-php-ext-install \ | |
gd \ | |
mcrypt \ | |
mysqli \ | |
pdo \ | |
pdo_mysql \ | |
mbstring \ | |
tokenizer \ | |
opcache \ | |
exif \ | |
zip \ | |
imagemagik | |
#Устанавливаем компосер | |
RUN curl -sS https://getcomposer.org/installer | php -- \ | |
--filename=composer \ | |
--install-dir=/usr/local/bin && \ | |
echo "alias composer='composer'" >> /root/.bashrc && \ | |
composer | |
#Устанавливаем Gitify | |
RUN cd /var/www && git clone https://github.com/modmore/Gitify.git Gitify && cd Gitify && composer install && chmod +x Gitify | |
#Gitify доступен через команду /var/www/Gitify/Gitify (init, extract) | |
#опеределяем рабочую папку | |
WORKDIR /var/www | |
RUN usermod -u 1000 www-data | |
#определяем рабочий порт | |
EXPOSE 9000 | |
CMD ["php"] | |
------------------------------------------------------------------------------------- | |
Создаем конфигурационный файл nginx | |
nano nginx/app.conf | |
код файла | |
--------------------- | |
server { | |
listen 80; | |
server_name localhost; | |
#charset koi8-r; | |
access_log /var/www/site/html/host.access.log main; | |
error_log /var/www/site/html/error.log; | |
root /var/www/site/html; | |
index index.php; | |
client_max_body_size 30M; | |
rewrite_log on; | |
autoindex on; | |
location / { | |
# Pretty URLs. Allows removal of "index.php" from the URL. | |
# Useful for frameworks like Laravel or WordPress. | |
try_files $uri $uri/ /index.php?$query_string; | |
} | |
# Turn off logging for favicon and robots.txt | |
location = /robots.txt { access_log off; log_not_found off; } | |
location = /favicon.ico { access_log off; log_not_found off; } | |
# serve static files directly | |
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { | |
access_log off; | |
expires max; | |
} | |
# Removes trailing slashes (prevents SEO duplicate content issues) | |
if (!-d $request_filename) | |
{ | |
rewrite ^/(.+)/$ /$1 permanent; | |
} | |
# Removes trailing "index" from all controllers. | |
# Useful for frameworks like Laravel. | |
if ($request_uri ~* index/?$) | |
{ | |
rewrite ^/(.*)/index/?$ /$1 permanent; | |
} | |
# Unless the request is for a valid file (image, js, css, etc.), | |
# send it to index.php | |
if (!-e $request_filename) | |
{ | |
rewrite ^/(.*)$ /index.php?/$1 last; | |
break; | |
} | |
location ~ \.php$ { | |
root /var/www/site/html; | |
try_files $uri =404; | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_pass php:9000; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
fastcgi_param PATH_INFO $fastcgi_path_info; | |
} | |
} | |
----------------------------------------------------------------------------------- | |
Запускаем сборку | |
docker-compose up -d | |
просмотр всех запущенных контейнеров docker ps | |
доступ к контейнеру | |
docker exec -i -t CONTAINER ID bash | |
Загружаем в папку app ModX | |
переходим по адресу http://0.0.0.0:8080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment