From ef8ce69dadfdd0ade66db07da11fb641acf9177d Mon Sep 17 00:00:00 2001 From: hugo gogo Date: Tue, 20 Sep 2022 21:10:45 +0200 Subject: [PATCH] wip trying to launch worpdress --- Makefile | 6 +- README.md | 6 +- srcs/docker-compose.yml | 6 +- srcs/requirements/mariadb/.dockerignore | 0 srcs/requirements/mariadb/Dockerfile | 2 + .../mariadb/conf/50-server.cnf.debian | 4 +- .../mariadb/conf/mariadb-server.cnf.alpine | 11 ++- srcs/requirements/nginx/.dockerignore | 0 srcs/requirements/nginx/Dockerfile | 60 ++++++++-------- .../nginx/conf/inception_nginx.conf | 23 +++--- srcs/requirements/test/.dockerignore | 0 srcs/requirements/test/Dockerfile | 51 ------------- srcs/requirements/test/tools/hello | Bin 142 -> 0 bytes srcs/requirements/test/tools/hello.asm | 16 ----- srcs/requirements/wordpress/Dockerfile | 68 +++++++++--------- .../wordpress/conf/wp_entrypoint.sh | 10 +-- 16 files changed, 105 insertions(+), 158 deletions(-) delete mode 100644 srcs/requirements/mariadb/.dockerignore delete mode 100644 srcs/requirements/nginx/.dockerignore delete mode 100644 srcs/requirements/test/.dockerignore delete mode 100644 srcs/requirements/test/Dockerfile delete mode 100755 srcs/requirements/test/tools/hello delete mode 100644 srcs/requirements/test/tools/hello.asm diff --git a/Makefile b/Makefile index 552a9e5..f5b7e6f 100644 --- a/Makefile +++ b/Makefile @@ -54,12 +54,14 @@ up: $(VOLUMES_D) list: @echo $(B_YELLOW)"\nimages:"$(RESET) @$(SUDO) docker images -a - @echo $(B_YELLOW)"\ncontainers:"$(RESET) - @$(SUDO) docker ps -a @echo $(B_YELLOW)"\nvolumes:"$(RESET) @$(SUDO) docker volume ls + @echo $(B_YELLOW)"\nvolumes content:"$(RESET) + @ls $(VOLUMES_D) @echo $(B_YELLOW)"\nnetworks:"$(RESET) @$(SUDO) docker network ls + @echo $(B_YELLOW)"\ncontainers:"$(RESET) + @$(SUDO) docker ps -a @echo "" # remove project images and containers not used diff --git a/README.md b/README.md index 7617d70..8df5988 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,8 @@ --- #### docker : -- [docker starter guide](https://docs.docker.com/get-started/) -- [docker compose volumes](https://docs.docker.com/compose/compose-file/#volumes) -- [docker glossaire](https://docs.docker.com/glossary/) -- [Dockerfile syntaxe](https://docs.docker.com/engine/reference/builder/) +- [docker compose man](https://docs.docker.com/compose/compose-file/#volumes) +- [Dockerfile man](https://docs.docker.com/engine/reference/builder/) - [determine the parent image](https://forums.docker.com/t/determine-the-parent-image/48611) - [docker image from scratch](https://codeburst.io/docker-from-scratch-2a84552470c8) - [build context and image context](https://stackoverflow.com/questions/55108649/what-is-app-working-directory-for-a-dockerfile/55109065#55109065) diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index 354053a..ab6d6e7 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -15,7 +15,7 @@ services: - inception ports: - "443:443" - - "80:80" +# - "80:80" build: ./requirements/nginx image: nginx container_name: nginx_container @@ -44,8 +44,8 @@ services: env_file: ./.env networks: - inception - volumes: - - wp_volume:/var/www/html +# volumes: +# - wp_volume:/var/www/html build: context: ./requirements/wordpress args: diff --git a/srcs/requirements/mariadb/.dockerignore b/srcs/requirements/mariadb/.dockerignore deleted file mode 100644 index e69de29..0000000 diff --git a/srcs/requirements/mariadb/Dockerfile b/srcs/requirements/mariadb/Dockerfile index d453329..2796928 100644 --- a/srcs/requirements/mariadb/Dockerfile +++ b/srcs/requirements/mariadb/Dockerfile @@ -2,9 +2,11 @@ # FROM debian:buster # +# # vim and bash for debug # RUN apt update && apt install -y \ # mariadb-client \ # mariadb-server \ +# vim bash \ # && \ # rm -rf /var/lib/apt/lists/* # diff --git a/srcs/requirements/mariadb/conf/50-server.cnf.debian b/srcs/requirements/mariadb/conf/50-server.cnf.debian index 240c501..59b4a77 100644 --- a/srcs/requirements/mariadb/conf/50-server.cnf.debian +++ b/srcs/requirements/mariadb/conf/50-server.cnf.debian @@ -23,8 +23,8 @@ # * Basic Settings # user = mysql -pid-file = /run/mysqld/mysqld.pid -socket = /run/mysqld/mysqld.sock +pid-file = /var/run/mysqld/mysqld.pid +socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql diff --git a/srcs/requirements/mariadb/conf/mariadb-server.cnf.alpine b/srcs/requirements/mariadb/conf/mariadb-server.cnf.alpine index f555689..76c0df4 100644 --- a/srcs/requirements/mariadb/conf/mariadb-server.cnf.alpine +++ b/srcs/requirements/mariadb/conf/mariadb-server.cnf.alpine @@ -2,6 +2,10 @@ # inception modifications : # # [mysqld] : +# < socket=/run/mysqld/mysqld.sock +# > +# +# [mysqld] : # < skip-networking = false # > skip-networking # --- @@ -11,7 +15,7 @@ # < port = 3306 # > # --- -# < socket=/var/lib/mysql/mysql.sock +# < socket=/run/mysqld/mysqld.sock # > # @@ -20,6 +24,7 @@ # this is read by the standalone daemon and embedded servers [server] +socket=/run/mysqld/mysqld.sock # this is only for the mysqld standalone daemon [mysqld] @@ -28,6 +33,10 @@ datadir = /var/lib/mysql port = 3306 socket=/run/mysqld/mysqld.sock +# sock was in : /run/mysqld/mysqld.sock +# mariadb thought it was in : /var/lib/mysql/mysql.sock +# so I made : ln -s /run/mysqld/mysqld.sock /var/lib/mysql/mysql.sock + # Galera-related settings [galera] # Mandatory settings diff --git a/srcs/requirements/nginx/.dockerignore b/srcs/requirements/nginx/.dockerignore deleted file mode 100644 index e69de29..0000000 diff --git a/srcs/requirements/nginx/Dockerfile b/srcs/requirements/nginx/Dockerfile index 7cbe053..6ac4862 100644 --- a/srcs/requirements/nginx/Dockerfile +++ b/srcs/requirements/nginx/Dockerfile @@ -1,39 +1,43 @@ # debian (~ 180s) -------------------------------------------- -# FROM debian:buster -# -# # vim for debug -# RUN apt update && apt install -y \ -# nginx openssl \ -# vim \ -# && \ -# rm -rf /var/lib/apt/lists/* -# -# # nginx conf -# COPY ./conf/nginx.conf.debian /etc/nginx/nginx.conf -# COPY ./conf/inception_nginx.conf /etc/nginx/conf.d/ + FROM debian:buster + + # vim for debug + RUN apt update && apt install -y \ + nginx openssl \ + vim \ + && \ + rm -rf /var/lib/apt/lists/* + + # nginx conf + COPY ./conf/nginx.conf.debian /etc/nginx/nginx.conf + COPY ./conf/inception_nginx.conf /etc/nginx/conf.d/ # alpine (~ 45s) --------------------------------------------- - FROM alpine:3.15 - - # vim and bash for debug - RUN apk update && apk add \ - nginx openssl \ - vim bash \ - && \ - rm -rf /var/cache/apk* - - # nginx conf - COPY ./conf/nginx.conf.alpine /etc/nginx/nginx.conf - COPY ./conf/inception_nginx.conf /etc/nginx/http.d/ - - # create user www-data and assign it to group www-data - RUN adduser -S www-data && \ - adduser www-data www-data +# FROM alpine:3.15 +# +# # vim and bash for debug +# RUN apk update && apk add \ +# nginx openssl \ +# vim bash \ +# && \ +# rm -rf /var/cache/apk* +# +# # nginx conf +# COPY ./conf/nginx.conf.alpine /etc/nginx/nginx.conf +# COPY ./conf/inception_nginx.conf /etc/nginx/http.d/ +# +# # create user www-data and assign it to group www-data +# RUN adduser -S www-data && \ +# adduser www-data www-data +# +# RUN mkdir -p /var/www/html # common ----------------------------------------------------- +RUN rm -rf /var/www/html/* + # personalized index.html COPY ./conf/index.html /data/www/ diff --git a/srcs/requirements/nginx/conf/inception_nginx.conf b/srcs/requirements/nginx/conf/inception_nginx.conf index b98343c..8d20e9b 100644 --- a/srcs/requirements/nginx/conf/inception_nginx.conf +++ b/srcs/requirements/nginx/conf/inception_nginx.conf @@ -1,12 +1,12 @@ # doc : https://nginx.org/en/docs/dirindex.html # WIP redirect http to https -server { - listen 80; - listen [::]:80; - server_name _; - return 301 https://$host$request_uri; -} +#server { +# listen 80; +# listen [::]:80; +# server_name _; +# return 301 https://$host$request_uri; +#} server { listen 443 ssl; # for ipv4, on port 443, specifying that accepted connections should works in ssl mode @@ -20,18 +20,15 @@ server { location / { try_files $uri $uri/ =404; # from /etc/nginx/sites-enabled/default : First attempt to serve request as file, then as directory, then fall back to displaying a 404 - root /data/www/; } # pass PHP scripts to FastCGI (PHP-FPM) server location ~ \.php$ { - try_files $uri =404; include fastcgi_params; - include /etc/nginx/fastcgi.conf; - - fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_index index.php; + fastcgi_pass wordpress:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - #fastcgi_pass wordpress:9000; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + + try_files $uri =404; } } diff --git a/srcs/requirements/test/.dockerignore b/srcs/requirements/test/.dockerignore deleted file mode 100644 index e69de29..0000000 diff --git a/srcs/requirements/test/Dockerfile b/srcs/requirements/test/Dockerfile deleted file mode 100644 index 178357b..0000000 --- a/srcs/requirements/test/Dockerfile +++ /dev/null @@ -1,51 +0,0 @@ -# find official images : https://hub.docker.com/search -#FROM ubuntu:18.04 -#FROM alpine:3.16.1 -#FROM debian:buster - -# basic test -# build with : sudo docker build --tag test . -# run with : sudo docker run test -# 'hello' in assembly found here : http://timelessname.com/elfbin/ -FROM scratch -COPY tools/hello / -CMD [ "/hello" ] - -## working -#FROM scratch -#WORKDIR / -#COPY hello / -#CMD [ "/hello" ] - -## working, when WORKDIR is absent, it's default is set to "/" -#FROM scratch -#COPY hello / -#CMD [ "/hello" ] - -## not working, when CMD execute in shell form, instead of exec form [] -#FROM scratch -#COPY hello / -#CMD /hello - -## not working, because c executable need library -#FROM scratch -#COPY hello_c / -#CMD [ "/hello_c" ] - -## not working, when executable is copied to ".", because WORKDIR value is not "." but "/" since we gave it a relativ path so it was build in top of the implicit absolut path "/" -#FROM scratch -#WORKDIR . -#COPY hello . -#CMD [ "hello" ] - -## not working, when WORKDIR is set to the present directory and executable is not copied, because the workdir is not the present directory but a directory in the file system of docker : executable need to be copied there to function -#FROM scratch -#WORKDIR /home/simplonco/Desktop/42/14_inception/inception/srcs/requirements/mariadb -#CMD [ "hello" ] - -## working, because "hello" is copied to "/" and execute from "/" -#FROM scratch -#WORKDIR . -#COPY hello / -#CMD [ "/hello" ] - diff --git a/srcs/requirements/test/tools/hello b/srcs/requirements/test/tools/hello deleted file mode 100755 index 2eeeb9d4d00cf94be2d2a62558028c8f3d74e841..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 142 zcmb<-^>JflWc0{X2+uFdN#SB*U}j)sU|?uyVBs(U(hNITfW+B`*AWT~Obi+ftPCt* zd5{zXPz?w#0y06E6(lCW0G3|@WGR=ftOdHrfPkYv~a I5;)rc051O*%K!iX diff --git a/srcs/requirements/test/tools/hello.asm b/srcs/requirements/test/tools/hello.asm deleted file mode 100644 index 0cc26b9..0000000 --- a/srcs/requirements/test/tools/hello.asm +++ /dev/null @@ -1,16 +0,0 @@ - SECTION .data -msg: db "Hi World",10 -len: equ $-msg - - SECTION .text - global main -main: - mov edx,len - mov ecx,msg - mov ebx,1 - mov eax,4 - int 0x80 - mov ebx,0 - mov eax,1 - int 0x80 - diff --git a/srcs/requirements/wordpress/Dockerfile b/srcs/requirements/wordpress/Dockerfile index 4029031..4806152 100644 --- a/srcs/requirements/wordpress/Dockerfile +++ b/srcs/requirements/wordpress/Dockerfile @@ -1,50 +1,50 @@ # debian ----------------------------------------------------- -# FROM debian:buster -# -# # bash and vim for debug -# RUN apt update && apt install -y \ -# php7.3 \ -# php7.3-fpm \ -# php7.3-mysqli \ -# curl \ -# bash vim -# RUN rm -rf /var/lib/apt/lists/* -# -# # fpm config -# COPY ./conf/www.conf /etc/php/7.3/fpm/pool.d/ -# RUN mkdir /run/php/ -# -# ENV PHP_VERSION="php-fpm7.3" - -# alpine ----------------------------------------------------- - - FROM alpine:3.15 + FROM debian:buster # bash and vim for debug - RUN apk update && apk add \ - php7 \ - php7-fpm \ - php7-mysqli \ - php7-phar \ - php7-json \ + RUN apt update && apt install -y \ + php7.3 \ + php7.3-fpm \ + php7.3-mysqli \ curl \ bash vim RUN rm -rf /var/lib/apt/lists/* # fpm config - COPY ./conf/www.conf /etc/php7/php-fpm.d/ + COPY ./conf/www.conf /etc/php/7.3/fpm/pool.d/ RUN mkdir /run/php/ - # create wp directory - ARG WP_DIR - RUN mkdir -p ${WP_DIR} + ENV PHP_VERSION="php-fpm7.3" - # create www-data user and add to group - RUN adduser -S www-data && \ - adduser www-data www-data +# alpine ----------------------------------------------------- - ENV PHP_VERSION="php-fpm7" +# FROM alpine:3.15 +# +# # bash and vim for debug +# RUN apk update && apk add \ +# php7 \ +# php7-fpm \ +# php7-mysqli \ +# php7-phar \ +# php7-json \ +# curl \ +# bash vim +# RUN rm -rf /var/lib/apt/lists/* +# +# # fpm config +# COPY ./conf/www.conf /etc/php7/php-fpm.d/ +# RUN mkdir /run/php/ +# +# # create wp directory +# ARG WP_DIR +# RUN mkdir -p ${WP_DIR} +# +# # create www-data user and add to group +# RUN adduser -S www-data && \ +# adduser www-data www-data +# +# ENV PHP_VERSION="php-fpm7" # common ----------------------------------------------------- diff --git a/srcs/requirements/wordpress/conf/wp_entrypoint.sh b/srcs/requirements/wordpress/conf/wp_entrypoint.sh index 5f31d50..665c2da 100644 --- a/srcs/requirements/wordpress/conf/wp_entrypoint.sh +++ b/srcs/requirements/wordpress/conf/wp_entrypoint.sh @@ -1,10 +1,10 @@ #!/bin/sh -## install wordpress with cli : https://make.wordpress.org/cli/handbook/how-to-install/ +# install wordpress with cli : https://make.wordpress.org/cli/handbook/how-to-install/ mkdir -p ${WP_DIR} wp core download --path="${WP_DIR}" --allow-root -## create config file : +# create config file : wp config create \ --dbhost=mariadb \ --dbname="${DB_NAME}" \ @@ -12,7 +12,7 @@ wp config create \ --dbpass="${DB_PASS}" \ --path="${WP_DIR}" --allow-root -## install wordpress : +# install wordpress : wp core install \ --url="${WP_URL}" \ --title="${WP_TITLE}" \ @@ -22,11 +22,13 @@ wp core install \ --skip-email \ --path="${WP_DIR}" --allow-root -## create user : +# create user : wp user create \ "${WP_USER}" "${WP_USER_EMAIL}" \ --user_pass="${WP_USER_PSWD}" \ --path="${WP_DIR}" --allow-root + +# change owner and permissions to wp files chown -R www-data:www-data /var/www/* chmod 755 -R /var/www/*