Skip to content

Latest commit

 

History

History
125 lines (102 loc) · 4.85 KB

README.md

File metadata and controls

125 lines (102 loc) · 4.85 KB

Created by Kaushal Kishore
Original repo:https://github.com/kaushalkishorejaiswal/Docker-Centos-LEMP
Forked by Fuseteam
Email: [email protected]

Dockerfile for creating docker image for LEMP (Linux-Centos, Nginx mit PHP)

Steps for creating image from the Docker-LEMP:

Step 1 : Clone the clemp.git

Command: 
git clone https://github.com/fuseteam/clemp.git

Step 2 : Change the directory to the clone folder

Command:
cd clemp

Step 3 : Create the Docker Image

Command: 
sudo docker build -t ##NAME_OF_YOUR_DOCKER_IMAGE## .
Note : 
  a). This command will be fired where the DockerFile will be placed
  b). ##NAME_OF_YOUR_DOCKER_IMAGE## : Replace it with your image name
  c). . : (.) Symbols shows that your Dockerfile is available on the same directory where you are running the command.

Step 4 : Create an Nginx+PHP Installed Container from the image Command Syntax: sudo docker run --name [container name] -p [port to access (New Port):port exposed(original port)] -i -t [image name]

Command:
sudo docker run --name ##NAME_OF_YOUR_DOCKER_CONTAINER## -d -p 8082:80 -p3307:3306 ##NAME_OF_YOUR_DOCKER_IMAGE##

Step 5 : Now you can access your nginx container from your web browser.

Command:
http://127.0.0.1:8082/

Important Notes

  • You can get the IP of the container using the command
    • docker inspect ##Container ID##
  • To get the Container ID. Use the below command
    • docker ps -a
  • You can also access the Nginx using the container IP

Some other important commands:

  • docker images : To list all the images of your docker
  • docker ps : To list all the runing containers
  • docker kill ##CONTAINER_NAME## : To kill the runing container
  • docker rm ##CONTAINER_NAME## : To delete the container from the system.
  • docker inspect ##CONTAINER_NAME## : To get all the information about the container.
  • docker logs ##CONTAINER_NAME## : To get the logs of the container.
  • docker ps -a: To get the listing of all the containers.

Additional Notes:

docker images are used to create containers any changes to a container exists as long as the container is running changes in a container can be preserved by creating a new image from the container many containers can be created from one image

changes made in a container can be 'saved' by creating an image from that container with the following command Command Syntax: docker commit -m ""

Command Example:
docker commit -m "changed mysql to mariadb" webapp

database changes are not saved this way To persist database changes use docker volumes

Command for attaching the volume of your hosted machine:

Command Syntax:
sudo docker run --name ##NAME_OF_YOUR_DOCKER_CONTAINER## -d -p 8082:80 -v ##HOSTED_VOLUME_LOCATION##:##CONTAINER_VOLUME_LOCATION## ##YOUR_IMAGE_NAME##
Command Example:
sudo docker run --name nginx_ins -d -p 8082:80 -v /home/mysqldata:/var/lib/mysql clemp

any container that needs to make use of the same database should specify the database password via the PASSWORD enviroment variable, the container_run script makes it easier to do so. The docker volume can be sit anywhere including a different machine than the container runs on. See docker documentation for details. Additionally when moving the data directory the directory permissions should be preserved, otherwise subquentent databases will not be able to access it. The correct permissions can be verified after the first data directory is created with

ls -l

shell access to a container can be gained with the following command

docker exec -it ##container-name bash

containers can be stopped with the following command

docker stop ##container-name

stopped containers can be started again with the following command

docker start ##container-name

a prebuild image of this configuration can be pulled with the following command

docker pull fuseteam/clemp

Ngnix configuration

the nginx in this image is tailored for a specific folder structure, the following are configured in Nginx:

  • the document root is at /var/www
  • the directory index is at /var/www/view/index.html or index.php
  • /var/www has been added to the php include_path
  • a rewrite rule that redirects any url of the form /some-directory to /controller/index.php
  • a rewrite rule that redirects any url of the form /service/some.php to /controller/index.php