Devops's Blog

drupal in docker-compose

Создаем такую ирархию

					    
[root@vm druparcms] mkdir /opt/docker/druparcms/
[root@vm druparcms] ls -l /opt/docker/druparcms/
итого 12
-rw-r--r-- 1 root             root  836 сен 22 21:20 docker-compose.yml
drwxr-xr-x 8 systemd-coredump root 4096 сен 29 17:55 mysqldb
drwxr-xr-x 2 root             root   67 сен 22 20:53 nginx-conf
drwxr-xr-x 9 root             root 4096 сен 22 21:37 web
					    
					    
				    

Ложим конфиг nginx ,в нем заменяем на свои серты и выставляем свой server_name


[root@vm druparcms] ls /opt/docker/druparcms/nginx-conf/
domain.key  drupalize.conf  fullchain.crt
[root@vm druparcms] cat /opt/docker/druparcms/nginx-conf/drupalize.conf
server {
    listen 80;

    server_name dp_docker.web.s7.ru;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name dp_docker.web.s7.ru;
    ssl_certificate /etc/nginx/conf.d/fullchain.crt;
    ssl_certificate_key  /etc/nginx/conf.d/domain.key;

    root /var/www/html;

    index index.html index.htm index.nginx-debian.html index.php;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; allow all; }
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
        expires max;
        log_not_found off;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass phpfpm:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
				    

Скачиваем последнию версию drupal и ложим в каталог web


[root@vm druparcms]# wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
--2022-09-29 18:43:41--  https://www.drupal.org/download-latest/tar.gz
Распознаётся www.drupal.org (www.drupal.org)… 151.101.114.217
Подключение к www.drupal.org (www.drupal.org)|151.101.114.217|:443... соединение установлено.
HTTP-запрос отправлен. Ожидание ответа… 302 Moved Temporarily
Адрес: https://ftp.drupal.org/files/projects/drupal-9.4.7.tar.gz [переход]
--2022-09-29 18:43:42--  https://ftp.drupal.org/files/projects/drupal-9.4.7.tar.gz
Распознаётся ftp.drupal.org (ftp.drupal.org)… 151.101.114.217
Подключение к ftp.drupal.org (ftp.drupal.org)|151.101.114.217|:443... соединение установлено.
HTTP-запрос отправлен. Ожидание ответа… 200 OK
Длина: 21610800 (21M) [application/octet-stream]
Сохранение в: «drupal.tar.gz»

drupal.tar.gz                                               100%[========================================================================================================================================>]  20,61M  6,20MB/s    за 3,3s

2022-09-29 18:43:45 (6,20 MB/s) - «drupal.tar.gz» сохранён [21610800/21610800]

[root@vm druparcms]# tar -zxf drupal.tar.gz
[root@vm druparcms]# mv drupal
drupal-9.4.7/  drupal.tar.gz
[root@vm druparcms]# mv drupal-9.4.7/* web/
[root@vm druparcms]# rm -rf drupal*
[root@vm druparcms]# ls
docker-compose.yml  mysqldb  nginx-conf  web
[root@vm druparcms]# ls web/
autoload.php  composer.json  composer.lock  core  example.gitignore  index.php  INSTALL.txt  LICENSE.txt  modules  profiles  README.md  robots.txt  sites  themes  update.php  vendor  web.config

Сам фаил docker-compose.yml


[root@vm druparcms]# cat docker-compose.yml
version: "3"

services:
  mysql:
    image: mysql:8.0.30
    container_name: mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: 12345678
      MYSQL_DATABASE: drupal
      MYSQL_USER: drupal
      MYSQL_PASSWORD: xckjvnie#$%vfmoeg
    networks:
      - external
    volumes:
      - ./mysqldb:/var/lib/mysql
  phpfpm:
    image: bitnami/php-fpm:7.4
    container_name: phpfpm
    restart: unless-stopped
    depends_on:
      - mysql
    networks:
      - external
    volumes:
      - ./web:/var/www/html
  nginx:
    image: nginx:1.20.1
    container_name: nginx
    restart: unless-stopped
    depends_on:
      - phpfpm
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./nginx-conf:/etc/nginx/conf.d
      - ./web:/var/www/html
    networks:
      - external

networks:
  external:
    driver: bridge

Запускаем docker-compose


[root@vm druparcms]# docker-compose up -d
Creating network "druparcms_external" with driver "bridge"
Pulling mysql (mysql:8.0.30)...
8.0.30: Pulling from library/mysql
051f419db9dd: Pull complete
7627573fa82a: Pull complete
a44b358d7796: Pull complete
95753aff4b95: Pull complete
a1fa3bee53f4: Pull complete
f5227e0d612c: Pull complete
b4b4368b1983: Pull complete
f26212810c32: Pull complete
d803d4215f95: Pull complete
d5358a7f7d07: Pull complete
435e8908cd69: Pull complete
Digest: sha256:b9532b1edea72b6cee12d9f5a78547bd3812ea5db842566e17f8b33291ed2921
Status: Downloaded newer image for mysql:8.0.30
Pulling phpfpm (bitnami/php-fpm:7.4)...
7.4: Pulling from bitnami/php-fpm
1d8866550bdd: Pull complete
8d14e577f135: Pull complete
Digest: sha256:f82198208f4a5024bb9aa7221c68092e5e532e58f396f0d2ad0c272a3765d828
Status: Downloaded newer image for bitnami/php-fpm:7.4
Pulling nginx (nginx:1.20.1)...
1.20.1: Pulling from library/nginx
b380bbd43752: Pull complete
83acae5e2daa: Pull complete
33715b419f9b: Pull complete
eb08b4d557d8: Pull complete
74d5bdecd955: Pull complete
0820d7f25141: Pull complete
Digest: sha256:a98c2360dcfe44e9987ed09d59421bb654cb6c4abe50a92ec9c912f252461483
Status: Downloaded newer image for nginx:1.20.1
Creating mysql ... done
Creating phpfpm ... done
Creating nginx  ... done
[root@vm druparcms]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS         PORTS                                                                      NAMES
b2eff28510bd   nginx:1.20.1          "/docker-entrypoint.…"   6 seconds ago   Up 5 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp   nginx
9e8d5d273f6f   bitnami/php-fpm:7.4   "php-fpm -F --pid /o…"   7 seconds ago   Up 5 seconds   9000/tcp                                                                   phpfpm
d8c3e7987b93   mysql:8.0.30          "docker-entrypoint.s…"   7 seconds ago   Up 6 seconds   3306/tcp, 33060/tcp                                                        mysql

Запуск

image

Внесем изменения которые попросит установщик


[root@vm druparcms]# mkdir -p /opt/docker/druparcms/web/sites/default/files/translations
[root@vm druparcms]# cp /opt/docker/druparcms/web/sites/default/default.settings.php /opt/docker/druparcms/web/sites/default/settings.php
[root@vm druparcms]# chmod -R 777 /opt/docker/druparcms/web/sites/default/

Вносим необходимые данные и вконце заводим админский пароль

image

Установка завершена

image