Установка докера
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04-ru
Установка и использование Docker Compose в Ubuntu 20.04
https://docs.docker.com/compose/install/
New project
Структура папок:
- docker
- server
PHP
Путь к каталогу docker/php/Dockerfile
Dockerfile
FROM webdevops/php-apache-dev:7.4
WORKDIR /tmp/
COPY ./run_script /tmp/
CMD /tmp/run_script
RUN chmod +x run_script
WORKDIR /var/www/html
Путь к каталогу docker/php/run_script
run_script
#!/bin/bash
RED='\033[0;31m'
NC='\033[0m'
printf "╔═══╦══╦══╗╔═══╦═══╦══╦╗╔╦═══╗\n"
printf "║╔═╗╠╗╔╣╔╗║║╔══╣╔═╗║╔╗║║║║╔═╗║\n"
printf "║╚═╝║║║║║║║║║╔═╣╚═╝║║║║║║║╚═╝║\n"
printf "║╔══╝║║║║║║║║╚╗║╔╗╔╣║║║║║║╔══╝\n"
printf "║║──╔╝╚╣╚╝║║╚═╝║║║║║╚╝║╚╝║║\n"
printf "╚╝──╚══╩══╝╚═══╩╝╚╝╚══╩══╩╝\n"
supervisord
MySQL
Путь к каталогу docker/mysql/Dockerfile
Dockerfile
FROM mysql:5.7
COPY ./my.cnf /etc/mysql/my.cnf
Путь к каталогу docker/mysql/my.cnf
my.cnf
[mysqld]
max_allowed_packet=256M
skip-character-set-client-handshake
character-set-server=utf8
collation-server=utf8_general_ci
init-connect = SET NAMES utf8
explicit_defaults_for_timestamp = 1
[client]
default-character-set=utf8
docker-compose.yml
Путь к файлу docker/docker-compose.yml
yaml
version: '3'
services:
a_level_nix_php:
build: ./php
container_name: a_level_nix_php
volumes:
- ../server:/var/www/html
ports:
- 8181:80
environment:
WEB_DOCUMENT_ROOT: /var/www/html/public
WEB_DOCUMENT_INDEX: index.php
PHP_MEMORY_LIMIT: 2G
PHP_UPLOAD_MAX_FILESIZE: 512M
PHP_POST_MAX_SIZE: 512M
PHP_DISPLAY_ERRORS: 1
php.xdebug.max_nesting_level: 500
depends_on:
- a_level_nix_mysql
a_level_nix_mysql:
build: ./mysql
container_name: a_level_nix_mysql
environment:
MYSQL_ROOT_PASSWORD: cbece_gead-cebfa
MYSQL_DATABASE: a_level_nix_mysql
ports:
- 3131:3306
volumes:
- a_level_nix-db:/var/lib/mysql
volumes:
a_level_nix-db:
phpmyadmin
Можно добавить в сервис phpmyadmin
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
restart: always
ports:
- '8088:80'
environment:
PMA_ARBITRARY: 0
PMA_HOST: 'a_level_nix_mysql'
MYSQL_ROOT_PASSWORD: 'cbece_gead-cebfa'
depends_on:
- a_level_nix_mysql
Команды для работы с докером
#start project
docker-compose up
docker-compose up -d
docker-compose up --build
#stop project
docker-compose stop
docker-compose down
#kill project
docker-compose kill
docker-compose down --rm=all
#docker bash
docker exec -it a_level_nix_php /bin/bash
#Problem private
sudo chown -R $USER server
docker system prune
docker image prune
docker container prune
docker rmi -f $(docker ps -a)
docker rmi -f $(docker images)