modified: z1/index.php
5.6 KiB
MY WEB APPLICATION
MADE WITH DOCKER
Notes manager where you can write each note you want with a maximum length of 60 characters, once you don’t want to see the note you can delete it
SOFTWARE NEEDED
- First and the most important you need to have docker installed.
- Installation -> https://www.docker.com/products/docker-desktop/
- In my case I interact with docker using the terminal of visual studio
- docker images:
- php:fpm-alpine
- nginx:alpine
- mysql:latest
- Volumes used: They are local directories:The directory data where you can find the local file of the data that is inserted in the database.
- Network: Same network used for the three containers docker compose will create automatically this network and will assign it to the three containers
- Git:
To make the git work via ssh you have to introduce the following commands
Once finish the configuration print the key and copy it into git. Here is how to get the keyssh-keygen -t rsa -b 4096 -C "rafael.saez.arana@student.tuke.sk"
Then you can add the remote repository and make pushcat key.pub
git init git remote add origin git@git.kemt.fei.tuke.sk:rs890nz/zkt24.git git add . git commit . -m 'commit all' git push git@git.kemt.fei.tuke.sk:rs890nz/zkt24.git
DEPLOYMENT
- DOCKER COMPOSE:
Using docker compose I specified all the images I am going to use for my application. This will create and execute the containers needed for my application, also it will create automatically the virtual network that will connect all of this containers, the name of the container will be also its name in the network.
In the next docker compose file is specified that I will have the containers php, nginx and my sql.
version: '3.8' services: php: build: context: ./php/ container_name: programwithgio-app restart: always volumes: - ./:/var/www/html nginx: build: context: ./nginx/ container_name: programwithgio-nginx restart: always volumes: - ./:/var/www/html depends_on: - php ports: - 8080:80 mysql: image: mysql:latest restart: always environment: MYSQL_ROOT_PASSWORD: password volumes: - ./data:/var/lib/mysql
MORE ABOUT DOCKER COMPOSE
-
php: I specified that I will build a container from a docker file that is in the folder php and also that templates(local location of the templates of the web application) will be mapped to /var/www/html/ inside the container.
- DOCKERFILE PHP:
FROM php:fpm-alpine RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
- DOCKERFILE PHP:
-
nginx: I specified that it is build from a Dockerfile and it is dependent on php and that the port is going to be 8080 in my machine and 80 in the container
- DOCKERFILE NGINX:
FROM nginx:alpine COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
- Default.conf:
server { listen 80 default_server; root /var/www/html; index index.html index.php; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } access_log off; error_log /var/log/nginx/error.log error; sendfile off; client_max_body_size 100m; location ~ .php$ { fastcgi_split_path_info ^(.+.php)(/.+)$; fastcgi_pass php:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_read_timeout 300; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors off; fastcgi_buffer_size 16k; fastcgi_buffers 4 16k; } location ~ /.ht { deny all; } }
- DOCKERFILE NGINX:
-
mysql: I specified that the password for the user root(is by default) is going to be password and also I mapped the local database data to /var/lib/mysql inside the container to be sure that once the container is shot down the data is in somewhere
- CONNECT TO THE DATABASE WHILE RUNNING
- We can connect to the database while running to create the database table and atrributes
- Connection:
docker exec -it mysql-server mysql -uroot -p
- SQL code for creating the database
CREATE DATABASE NOTAS; CREATE TABLE nota ( id VARCHAR(60), noteContent VARCHAR(60) );
- CONNECT TO THE DATABASE WHILE RUNNING
HOW TO START,STOP AND REMOVE THE APP
- Prepare and star the app via the command bash start-app.sh
Docker will build and execute the containers with the info given in docker compose file (-d is set to execute in detached mode)
- Start-app.sh:
docker-compose up -d
- Stop the app via bash stop-app.sh
- Stop-app.sh:
docker-compose stop
- Remove the app via bash remove-app.sh
- Remove-app.sh:
docker-compose down
VIEW THE APP IN THE WEB
Once you have download all the requiered software and you use bash start-app and everything is done you can see the web application searching localhost:8080