Thursday, December 2, 2021

NPM and docker installation and few commands

 NPM Installation

================

sudo apt install nodejs

sudo apt install npm


nodejs -v

(version)

npm -v

(Version)


sudo apt install build-essential

(install build essentials in case you want to compile code from source -- just to be make sure)

An alternative to installing Node.js with apt is to use a tool called nvm, which stands for “Node.js Version Manager”. Rather than working at the operating system level, nvm works at the level of an independent directory within your home directory. This means that you can install multiple self-contained versions of Node.js without affecting the entire system.



Docker installation

====================

sudo apt install docker.io


docker -v 

(version)

Just in case apt fails to install docker there is an alternative to intall snap and install docker from there... also to know about snap google it 


sudo apt install snap

sudo snap install docker


[some handy commands] ...google for more 

docker run hello-world

docker images

docker ps -a

docker ps

docker build ./

docker run -tid -p 8083:90 --name "work" a334445434

docker exec -it kantil bash

docker cp /root/var/www/html/test.php work:/var/www/html

docker exec 74f86665f0fd ls

chmod -R 755 /var/www/html

dockerfile basic example with apache and php php:7.4-apache

Create a docker file 

FROM php:7.4-apache

RUN echo "Building the Image"

COPY /var/www/html /var/www/html

RUN chmod -R 755 /var/www/html

EXPOSE 80


Rest of the commands

docker build ./

docker run -tid -p 8083:90 --name "work" a334445434

docker exec -it kantil bash

(exit to get out of bash)

This wont sync files dynamically into container after changes - but only onces

Wednesday, December 1, 2021

Run php page inside docker container using docker commands

 Run php page inside docker container using docker commands

===========================


docker run -tid -v /root/var/www/html:/var/www/html -p 8080:80 --name="phpserver" php:7.4-apache

(you have to upload a test.php file in /html location  and image is downloaded automatically if not available for php:7.4-apache)

docker ps

(above to get container id as container is created)

(gives file permisson -- but have to run everytime if you modify test.php or any other file in html folder) 

docker exec 20ea72577d44 chmod -R 755 /var/www/html


Run in url : http://[your local host address]/test.php