{"id":19098509,"url":"https://github.com/ucfopen/fuelphp-crash-course-docker","last_synced_at":"2025-02-22T09:30:14.786Z","repository":{"id":42411195,"uuid":"62081674","full_name":"ucfopen/fuelphp-crash-course-docker","owner":"ucfopen","description":"Easy Docker setup for running the FuelPHP crash course","archived":false,"fork":false,"pushed_at":"2016-06-30T19:09:18.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-01-03T00:51:38.610Z","etag":null,"topics":["docker","fuel","fuelphp","php","tutorial"],"latest_commit_sha":null,"homepage":null,"language":"Nginx","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ucfopen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-27T19:18:55.000Z","updated_at":"2019-07-19T13:39:25.000Z","dependencies_parsed_at":"2022-09-04T06:03:30.517Z","dependency_job_id":null,"html_url":"https://github.com/ucfopen/fuelphp-crash-course-docker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucfopen%2Ffuelphp-crash-course-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucfopen%2Ffuelphp-crash-course-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucfopen%2Ffuelphp-crash-course-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucfopen%2Ffuelphp-crash-course-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ucfopen","download_url":"https://codeload.github.com/ucfopen/fuelphp-crash-course-docker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240152178,"owners_count":19756038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","fuel","fuelphp","php","tutorial"],"created_at":"2024-11-09T03:46:08.424Z","updated_at":"2025-02-22T09:30:14.738Z","avatar_url":"https://github.com/ucfopen.png","language":"Nginx","readme":"# FuelPHP Crash Course Docker\n\n## Table of Contents\n  1. Contributors\n  2. Introduction\n    - Authors\n    - Prerequisite Knowledge\n    - Included Files\n  3. Part 1: Getting Started (Installation and Setup)\n    - Installing Virtual Box\n    - Installing Docker Components with Homebrew\n    - Setting Up the Machine\n    - Testing Docker\n  4. Part 2: Setting Up a LEMP Server\n    - Docker Compose\n    - Editing docker-file.yml\n      - Version\n      - Services\n      - Image\n      - Ports\n      - Volumes\n      - Links\n      - Build and Dockerfiles\n      - Environment\n    - Creating a Dockerfile\n      - From\n      - Run\n    - Configuring the LEMP Stack\n    - Testing the LEMP Stack\n  5. More practice\n\n## Contributors\n  - [Sam Belcastro](https://github.com/samuel-belcastro/)\n\n## Introduction\nDocker is an open platform that allows developers to use a virtualization\nmethod called containerization. Containerization allows distributed software\nto run without running an entire virtual machine for each application.\n\n**Prerequisite Knowledge**\n\nIn order to be successful in comprehending this tutorial, having knowledge in\nthe following will help. The bolded items are especially important.\n  - **HTML, CSS, Javascript, and PHP**\n  - Github\n  - **Nginx Configuration**\n  - PHP Configuration\n  - MySQL Configuration\n  - FastCGI\n\n**Included Files**\n\nThe files within this repository represent a completed version of this\ntutorial.\n\nThe only files that must be downloaded are:\n\n- *nginx.conf*\n- *default.conf**\n\nEverything else will be created during the tutorial.\n\n## Part 1: Getting Started (Installation and Setup)\n  Docker is built to work with Linux based Kernels. Therefore, a virtual machine is\n  required to develop with Docker on Mac OSX. Luckily, Docker realizes the\n  struggle involved with this, and makes using the virtual machine as easy as\n  possible!\n\n  1. Installing Virtual Box\n\n    In this tutorial, we will be using Virtual Box. Navigate to\n    http://www.virtualbox.org/ and download the latest version of Virtual Box.\n\n  2. Installing Docker Components with Homebrew\n\n    Docker offers a nice tool called Docker Toolbox, but, for this tutorial, we\n    are going to get our hands dirty and dive directly into the terminal!\n\n    The first Docker tool we are going to install is the docker engine.\n\n    Install docker with the following command:\n    ```\n      $ brew install docker\n    ```\n\n    Next, we want to install docker machine. Docker machine will allow us to\n    use docker seamlessly with Virtual Box.\n\n    Install docker machine with the following command:\n    ```\n      $ brew install docker-machine\n    ```\n\n    Finally, we want to install docker compose. Docker compose allows us to\n    build and link docker containers, along with mounting directories\n    from the host machine to the containers, with a single .yaml file!\n\n    After setting up docker compose, we will be able to launch our whole web\n    server with one command!\n\n    Install docker compose with the following command:\n    ```\n      $ brew install docker-compose\n    ```\n\n  5. Setting Up the Virtual Machine\n\n    The first thing we want to do when setting up a machine is check which\n    machines we have already created. To do this we simply type the following\n    command:\n\n    ```\n      $ docker-machine ls\n\n      NAME   ACTIVE   DRIVER  STATE   URL   SWARM   DOCKER   ERRORS\n    ```\n\n    There is nothing in the table output because we have not created any\n    machines yet!\n\n    In order to create our own machine we are going to run the following\n    command:\n\n    ```\n      $ docker-machine create --driver virtualbox default\n    ```\n\n    Let's analyze this command:\n\n    **docker-machine** - tells the OS to run the docker-machine program\u003cbr /\u003e\n    **create** - calls the create subcommand, which creates a new virtual\n    machine\u003cbr /\u003e\n    **--driver virtualbox** - tells docker-machine that we are using Virtual\n    Box\u003cbr /\u003e\n    **default** - names the machine default\u003cbr /\u003e\n\n    After creating the machine, run:\n\n    ```\n      $ docker-machine ls\n\n      NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER   ERRORS\n      default   *        virtualbox   Running   tcp://IP_OF_MACHINE:PORT            v1.11.2     \n    ```\n    Congratulations! The machine is now successfully created. There is now only\n    one step left in order to seamlessly use our docker machine.\n\n    Run the following command:\n\n    ```\n      $ eval \"$(docker-machine env default)\"\n    ```\n\n    This command will connect your shell to the new machine. Now every time\n    you use the **docker** command, it will direct it towards the machine.\n    We can replace *default* with any machine name.\n\n    **This command must be ran every time you start the machine!**\n\n\n  4. Testing Docker\n\n    Now that we have successfully installed Docker and set up a machine, we\n    will make sure the core engine is working.\n\n    Run the command:\n    ```\n      $ docker run hello-world\n    ```\n\n    Let's analyze this command:\u003cbr /\u003e\n      **docker** - Tells the OS that you are using the docker program\u003cbr /\u003e\n      **run** - A subcommand that creates and runs a docker container\u003cbr /\u003e\n      **hello-world** - The image to be loaded into the container\u003cbr /\u003e\n\n    Each container requires an image to run. For example, our web server\n    container is going to use Linux Alpine as the guest OS, and we can build\n    our container with the Linux Alpine image.\n\n    So, how does docker know where to get the image? Docker checks (in order):\n      1. Local Images already installed through Docker\n      2. **DockerHub** - public repository for Docker images\n\n    Docker will then install the image if the image is on DockerHub.   \n\n    For this tutorial, we pulled *hello-world* from DockerHub, and Docker built\n    a container to hold and run it in. This program **is not** running on the\n    host OS!\n\n## Part 2: Setting Up a LEMP Server\n\n  For this tutorial, LEMP stands for Linux Nginx MySQL PHP. We are going to\n  create a stack of these services in order to serve our advanced web needs!\n\n  Before Docker, a typical way to implement a LEMP stack would be loading a\n  version of Linux to a physical or virtual machine, and independently\n  installing each service with its respective environment variables and\n  dependencies. If your super awesome web app became popular enough, you would\n  probably need to scale, and to do that you would have to... haha good luck\n  figuring that out!\n\n  With Docker and its containerization, we can create independent services,\n  running in their own little environment, with their own dependencies to\n  worry about. They can also be scaled fairly easily.\n\n  1. Docker Compose\n\n  I know what you're thinking, \"YES! WE FINALLY GET TO USE DOCKER COMPOSE!, \"\n  and right you are my friend... right you are.\n\n  The tutorial above shows how to create a basic container with an image from\n  Dockerhub, but it does not show how to install dependencies and edit config\n  files within that container. While that can all be done in the command line,\n  we don't have time for that!! We are going to knock out all of our container\n  customization in a nice file named *docker-compose.yml*.\n\n  To begin, let's open our terminal and run the command:\n\n  ```\n    $ mkdir myDocker\n  ```\n\n  This command can be ran in any directory, preferably a project directory.\n  The directory can also have any desired name.\n\n  Now that we have a directory for our project, let's create a\n  *docker-compose.yml*.\n\n  This file may be edited in any text editor, but it must reside the the\n  root of the directory that was previously created.\n\n  2. Editing docker-file.yml\n\n  Now, we will work on the *docker-compose.yml* file one section at a time.\n  **SPACES MATTER IN THIS FILE**\n\n  **Version**\n\n    The *docker-compose.yml* always start with a version number. For this\n    tutorial, we will be using version 2.\n\n    ```\n      1| version: '2'\n    ```\n\n  **Services**\n\n    Following version, we will begin to define each service we would like\n    docker to create. This is where we design our containers.\n\n    ```\n      1| version: '2'\n      2|\n      3| services:\n    ```\n\n    For this tutorial, we will be creating a container for Nginx, PHP, and\n    MySQL.\n\n    We will start with Nginx\n\n    ```\n      1| version: '2'\n      2|\n      3| services:\n      4|  nginx:\n    ```\n\n    **Image**\n\n    For Nginx we will need an image. The image we are going to use is\n    *nginx:stable-alpine* from Dockerhub\n\n    This is the same as running the *docker run* command in the\n    terminal. When the *docker-compose.yml* file is compiled and executed,\n    the container being created will look for a local image and then proceed\n    to Dockerhub if the local image does not exist.\n\n    ```\n      1| version: '2'\n      2|\n      3| services:\n      4|  nginx:\n      5|   image: nginx:stable-alpine\n    ```\n\n    **Ports**\n\n    We will also need to set Nginx to listen to the host machine's port 80.\n    Remember that the container is acting as it's own separate machine.\n\n    So how do we link Nginx's port 80 to the host machines port 80? Linking\n    the two ports is actually pretty simple!\n\n    ```\n      1| version: '2'\n      2|\n      3| services:\n      4|  nginx:\n      5|   image: nginx:stable-alpine\n      6|   ports:\n      7|    - \"80:80\"\n    ```\n    At this point, we have designed a container that will run an Nginx\n    webserver.\n\n    Open the terminal, and run the command:\n\n    ```\n      $ docker-compose up\n    ```\n\n    Docker Compose will look for the *docker-compose.yml* file, and then it\n    will build the containers for the services we have listed in our file with\n    the settings we have defined.\n\n    If you run the *docker-machine ls* command, and type the IP of your\n    machine (without the port) into your browser, you will see the default\n    Nginx homepage!\n\n    **Volumes**\n\n    However, we are still missing one crucial component of web development. We\n    need a place to store all of our files to be served by Nginx.\n\n    Nginx creates a default directory for these files, but we still are not\n    able to add or modify files in that directory efficiently. To solve this\n    problem, we are going to map the directory created within our container to\n    a directory within our host machine. This way we can edit our files in\n    our favorite editor without needing to constantly upload our files to the\n    container.\n\n    ```\n      1| version: '2'\n      2|\n      3| services:\n      4|  nginx:\n      5|   image: nginx:stable-alpine\n      6|   ports:\n      7|    - \"80:80\"\n      8|   volumes:\n      9|    - ./app/public:/var/www/html/public:ro\n    ```\n\n    Now, when we build this container, everything within our\n    *myDocker/app/public* directory will go the */var/www/html/public*\n    directory within the container. Each time we edit or add a file,\n    the container will follow the same action. You just have to refresh the\n    page!\n\n    Being able to edit out config files for the web server would also be a\n    nice addition to our container. To do this we will just map the specific\n    config files in the same manner as we did with directory above.\n\n    ```\n      1| version: '2'\n      2|\n      3| services:\n      4|  nginx:\n      5|   image: nginx:stable-alpine\n      6|   ports:\n      7|    - \"80:80\"\n      8|   volumes:\n      9|    - ./app/public:/var/www/html/public:ro\n     10|    - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro\n     11|    - ./config/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf:ro\n    ```\n\n    Here we linked two of Nginx's default configuration files. If we need to\n    edit any of the default configuration files, we now have a way to do so\n    from our host machine.\n\n    As of right now, we have designed a container that acts as a fully\n    functional web server that can serve HTML, CSS, and Javascript files. We\n    also have the power to edit files right from our host machine. This\n    includes project files, and configuration files.\n\n    **Note: When editing configuration files, the web server must be restarted\n    for changes to take effect. Restarting the web server is done by stopping\n    the container in the terminal (control + C), and then re-composing the\n    container (docker-compose up).**\n\n    **Links**\n\n    Finally, since we do not want to run the whole stack in a single container,\n    we will need to tell the Nginx container to link to other containers.\n\n    When Docker creates a new container, Docker assigns the container an IP\n    address. When a container is stopped and ran again, the container gets\n    assigned a different IP. It is a bad idea to link containers via their\n    IP because of the inconsistency with the IP assignments. To combat this\n    issue, Docker provides a hosts file where Docker links the container name\n    to its IP. This allows us to link by name, and let Docker figure everything\n    else out.  \n\n    For this tutorial, we will be linking to a phpfpm container. This\n    container will be explained further as we design the next service, but\n    for now just add the link to your *docker-compose.yml* file.\n\n    ```\n      1| version: '2'\n      2|\n      3| services:\n      4|  nginx:\n      5|   image: nginx:stable-alpine\n      6|   ports:\n      7|    - \"80:80\"\n      8|   volumes:\n      9|    - ./app/public:/var/www/html/public:ro\n     10|    - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro\n     11|    - ./config/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf:ro\n     12|  links:\n     12|    - phpfpm\n    ```\n\n    Now we will proceed to the phpfpm container.\n\n    We require a phpfpm service for Nginx to turn to when Nginx receives a\n    PHP request. Nginx does not know how to handle PHP, but Nginx is willing to\n    learn how to direct PHP requests through some configuration, which will be\n    addressed later. For now, we will design the PHP service.\n\n    In summary, this service will receive a PHP request from Nginx through\n    FastCGI, and return a response back to Nginx.\n\n    **Build and Dockerfiles**\n\n    We will begin by adding phpfpm to our list of services.\n\n    ```\n      1| version: '2'\n      2|\n      3| services:\n      4|  nginx:\n      5|   image: nginx:stable-alpine\n      6|   ports:\n      7|    - \"80:80\"\n      8|   volumes:\n      9|    - ./app/public:/var/www/html/public:ro\n     10|    - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro\n     11|    - ./config/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf:ro\n     12|   links:\n     12|    - phpfpm\n     13|  \n     14|  phpfpm\n    ```  \n\n    PHP has many extensions, and we may not want to waste space and resources\n    on ones we don't need. These extensions can also be very specific to what\n    is trying to be accomplished. Docker allows us to create our own image\n    based on already existent images. To do this we use a *Dockerfile*. We will\n    create this *Dockerfile* after finishing our *docker-compose.yml*.\n\n    To notify docker-compose that we are building our own image, we use *build*\n    instead of *image*.  \n\n    ```\n      1| version: '2'\n      2|\n      3| services:\n      4|  nginx:\n      5|   image: nginx:stable-alpine\n      6|   ports:\n      7|    - \"80:80\"\n      8|   volumes:\n      9|    - ./app/public:/var/www/html/public:ro\n     10|    - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro\n     11|    - ./config/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf:ro\n     12|   links:\n     13|    - phpfpm\n     14|  \n     15|  phpfpm\n     16|   build:\n    ```\n\n    We also need to tell docker-compose where to find our Dockerfile, so\n    docker-compose to correctly communicate to Docker where to build from.\n\n    To do this, we give docker-compose a *context* and the path to the\n    *Dockerfile* relative to that context.\n\n    ```\n      1| version: '2'\n      2|\n      3| services:\n      4|  nginx:\n      5|   image: nginx:stable-alpine\n      6|   ports:\n      7|    - \"80:80\"\n      8|   volumes:\n      9|    - ./app/public:/var/www/html/public:ro\n     10|    - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro\n     11|    - ./config/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf:ro\n     12|   links:\n     13|    - phpfpm\n     14|  \n     15|  phpfpm\n     16|   build:\n     17|    context: .\n     18|    dockerfile: docker_files/Dockerfile.phpfpm\n     19|   ports:\n     20|    - \"9000:9000\"\n    ```\n\n    FastCGI is going to communicate with phpfpm on port 9000, and, since we\n    already defined and explained ports, we just tagged it on after build.\n\n    **Note: For this tutorial, we only use one Dockerfile, but we are setting\n    up the project as if we had 2 or more Dockerfiles.**\n\n    Now we can move on to environment variables!!\n\n    **Environment**\n\n    We did not have to set environment variables for our Nginx service, but,\n    since we are using MySQL, we will be required to set some for phpfpm.\n\n    Defining environment variables is also a relatively simple process. We are\n    going to define four variables, and they will define how we interact with\n    our MySQL container.\n\n    ```\n      1| version: '2'\n      2|\n      3| services:\n      4|  nginx:\n      5|   image: nginx:stable-alpine\n      6|   ports:\n      7|    - \"80:80\"\n      8|   volumes:\n      9|    - ./app/public:/var/www/html/public:ro\n     10|    - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro\n     11|    - ./config/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf:ro\n     12|   links:\n     13|    - phpfpm\n     14|  \n     15|  phpfpm\n     16|   build:\n     17|    context: .\n     18|    dockerfile: docker_files/Dockerfile.phpfpm\n     19|   ports:\n     20|    - \"9000:9000\"\n     21|   environment:\n     22|    - DB_HOST=mysql\n     23|    - DB_NAME=fuel\n     24|    - DB_USER=user\n     25|    - DB_PASS=secret\n    ```\n\n    Let's dissect these variables!\n\n    **DB_HOST** - the address of the mysql server. Due to the inconsistency in\n    IP assignment when creating docker containers, we use the name of the\n    container instead of hardcoding an IP address.\u003cbr /\u003e\n    **DB_NAME** - The name of the database that will be accessed\u003cbr /\u003e\n    **DB_USER** - The user that will be accessing the database\u003cbr /\u003e\n    **DB_PASS** - The password of the user accessing the database\u003cbr /\u003e\n\n    **Note: This file now contains a password. Beware when uploading code to\n    websites such as GitHub!!**\n\n    To wrap up this container, we are going to add mounted volumes like we did\n    with Nginx, and we will also add a link to the mysql container that we\n    will be building next!\n\n    ```\n      1| version: '2'\n      2|\n      3| services:\n      4|  nginx:\n      5|   image: nginx:stable-alpine\n      6|   ports:\n      7|    - \"80:80\"\n      8|   volumes:\n      9|    - ./app/public:/var/www/html/public:ro\n     10|    - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro\n     11|    - ./config/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf:ro\n     12|   links:\n     13|    - phpfpm\n     14|  \n     15|  phpfpm\n     16|   build:\n     17|    context: .\n     18|    dockerfile: docker_files/Dockerfile.phpfpm\n     19|   ports:\n     20|    - \"9000:9000\"\n     21|   environment:\n     22|    - DB_HOST=mysql\n     23|    - DB_NAME=fuel\n     24|    - DB_USER=user\n     25|    - DB_PASS=secret\n     26|   volumes:\n     27|    - ./app:/var/www/html:rw\n     29|   links:\n     30|    - mysql\n    ```\n\n    Finally, we are going to build a mysql container to handle all of our\n    databasing.\n\n    ```\n      1| version: '2'\n      2|\n      3| services:\n      4|  nginx:\n      5|   image: nginx:stable-alpine\n      6|   ports:\n      7|    - \"80:80\"\n      8|   volumes:\n      9|    - ./app/public:/var/www/html/public:ro\n     10|    - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro\n     11|    - ./config/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf:ro\n     12|   links:\n     13|    - phpfpm\n     14|  \n     15|  phpfpm\n     16|   build:\n     17|    context: .\n     18|    dockerfile: docker_files/Dockerfile.phpfpm\n     19|   ports:\n     20|    - \"9000:9000\"\n     21|   environment:\n     22|    - DB_HOST=mysql\n     23|    - DB_NAME=fuel\n     24|    - DB_USER=user\n     25|    - DB_PASS=secret\n     26|   volumes:\n     27|    - ./app:/var/www/html:rw\n     29|   links:\n     30|    - mysql\n     31|\n     32|  mysql\n     33|    image: mysql:5.5.47\n     34|    environment:\n     35|     - MYSQL_ROOT_PASSWORD=secret\n     36|     - MYSQL_USER=user\n     37|     - MYSQL_PASSWORD=secret\n     38|     - MYSQL_DATABASE=fuel\n     39|    ports:\n     40|     - \"3306:3306\"\n    ```\n\n    Just to recap what is going on here:\n\n    **image** : using mysql:5.5.47 image from Dockerhub to build our container\u003cbr /\u003e\n    **environment** : setting environment variables\u003cbr /\u003e\n    **ports** : telling the container to listen to the hosts port 3306 on its\u003cbr /\u003e\n    3306 port  \n\n    This concludes the creation of our *docker-compose.yml*! Keep in mind that\n    this is only the design of out docker containers. They will not be created\n    until we run the command:\n\n    ```\n      $ docker-compose up\n    ```\n\n    At this point, this command will generate an error because we have not\n    created the Dockerfile that our phpfpm container is going to build from.\n\n    That will be our next task!\n\n  3. Creating a Dockerfile\n\n    A *Dockerfile* is a file without any specific extension that Docker uses to\n    automate the process of building custom images. Unless explicitly stated,\n    Docker will look in the current directory for *Dockerfile* by default when\n    running the command:\n\n    ```\n      $ docker build\n    ```\n\n    Since we thought ahead, and created a directory called *docker_builds*, we\n    can decide to add more custom images later. We will place our docker file\n    in *docker_builds*, and we will name our file *Dockerfile.phpfpm*. We are\n    not required to add the *.phpfpm*, but it allows us to see which build\n    is in the Dockerfile.  \n\n    Finally, we can get to editing this Dockerfile!\n\n    **From**\n\n    Each Dockerfile requires a base image. These base images can come from\n    Dockerhub, or a private repository. In our case, the image is *php:5-fpm*\n    from Dockerhub, but an image can be anything as simple as a fresh linux\n    based operating system.\n\n    The base image is defined at the top of the Dockerfile:\n\n    ```\n      1| FROM php:5-fpm\n    ```\n\n    **Run**\n\n    Next, we are going to install any custom programs and extensions we want\n    to include for our specific container that are not in the base image.\n\n    For this project we are going to need:\n\n    **php5-mysql** - so we can communicate with our mysql container\n    **git** - so we can pull projects from github if needed\n    **zip / unzip** - allows us to use dependency managers such as Composer\n\n    We will write in the Dockerfile to tell docker to run a command in our\n    container upon creation that will install these programs.\n\n    ```\n      1| FROM php:5-fpm\n      2|\n      3| RUN apt-get -y update \u0026\u0026 apt-get install -y \\\n      4|   php5-mysql \\\n      5|   git \\\n      6|   zip \\\n      7|   unzip\n    ```\n\n    The -y tells *apt-get* to assume yes to all prompts when installing these\n    programs.\n\n    We could write this all in one line, but it is best practice to separate\n    each program with this syntax. The programs being installed are made clear,\n    and they are easily added and removed.\n\n    Next we want to install the extensions, so we add another RUN keyword.\n\n    ```\n      1| FROM php:5-fpm\n      2|\n      3| RUN apt-get -y update \u0026\u0026 apt-get install -y \\\n      4|   php5-mysql \\\n      5|   git \\\n      6|   zip \\\n      7|   unzip\n      9|\n     10| RUN docker-php-ext-install pdo pdo_mysql\n    ```\n\n    These last two commands are optional.\n\n    The first one installs Composer, a dependency manager for PHP MVC\n    frameworks such as FuelPHP. The second one gives the web user permission to\n    write to directories.\n\n    ```\n      1| FROM php:5-fpm\n      2|\n      3| RUN apt-get -y update \u0026\u0026 apt-get install -y \\\n      4|   php5-mysql \\\n      5|   git \\\n      6|   zip \\\n      7|   unzip\n      9|\n     10| RUN docker-php-ext-install pdo pdo_mysql\n     11|\n     12| RUN bash -c \"curl -sS https://getcomposer.org/installer | php \u0026\u0026 mv composer.phar /usr/local/bin/composer\"\n     13| RUN sed -i \"s/^www-data:x:[0-9]*/www-data:x:1000/\" /etc/passwd\n    ```\n\n    This concludes our Dockerfile!\n\n  4. Configuring our LEMP stack\n\n    This tutorial is intended to teach the basics of Docker. I have provided the\n    configuration files in order for this LEMP Stack to work in the repository.\n\n    There should two files (relative to the myDocker directory):\n\n      *config/nginx/nginx.conf*\u003cbr /\u003e\n      *config/nginx/conf.d/default.conf*\n\n    These files should be in the exact same locations as they are in the\n    repository, so our *docker-compose.yml* file can work.\n\n  5. Testing the LEMP stack\n\n    We have officially created a containerized LEMP stack, and we are ready to\n    test it!!!!\n\n    Go to the terminal, and type the following command:\n\n    ```\n      $ docker-machine ls\n    ```\n\n    Make sure your machine is running, and take note of the IP address\n    (without the port).\n\n    Assuming you are connected to your machine with\n\n    ```\n      $ eval \"$(docker-machine env default)\"\n    ```\n\n    you can run the command\n\n    ```\n      $ docker-compose up\n    ```\n\n    Docker will take a minute to build everything, but, after it finishes, go\n    to your browser and type the IP of your machine.\n\n    The Nginx default page should show up.\n\n    Create a new file with the name: *index.php*\n\n    Next write the following contents to the file:\n\n    ```\n      1| \u003c?php\n      2|    echo phpinfo();\n      3| ?\u003e\n    ```\n\n    Save the file to *app/public/* and refresh your page.\n\n    You should see the entire php configuration file put into a nicely\n    formatted webpage.\n\n## More Practice\n\nBy this point, we have enough knowledge to learn how to create a FuelPHP web\napplication using docker to host all of the web services. Checkout this\n[FuelPHP Crash Course w/ Docker](http://ucf.github.io/fuelphp-crash-course/)\ntutorial to gain some more experience with docker while creating a practical\napplication! XD\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fucfopen%2Ffuelphp-crash-course-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fucfopen%2Ffuelphp-crash-course-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fucfopen%2Ffuelphp-crash-course-docker/lists"}