Skip to content

sopinet/curso-intensivo-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker-skeleton-php

nginx mysql php5.6 php7.0 php7.1

Usage

  1. Copy .env.dist to .env:

    $ cp .env.dist .env
  2. If you plan to use the default docker repository to pull the Docker’s images, you can keep the default values of the PROJECT_NAMESPACE and REPOSITORY_NAME environment variables from the .env file and skip this step. Otherwise you need to build your own images. You can do that with:

    $ ./bin/build
  3. Start the container.

    $ docker-compose up -d
  4. Access your application via http://localhost/.

Install node and uglifycss / uglifyjs

curl -sL https://deb.nodesource.com/setup_6.x | bash apt-get install -y nodejs

npm install uglify-js2 -g

/usr/lib/node_modules/uglify-js2/bin/uglifyjs2

npm install uglifycss -g

/usr/lib/node_modules/uglifycss/uglifycss

NODE:

/usr/bin/nodejs

Documentation

Docker

Useful docker commands

# Start containers.
$ docker-compose up -d

# Restart services.
$ docker-compose restart

# List containers.
$ docker-compose ps

# Start a terminal session for <container_name> (i.e: php).
$ docker-compose exec <container_name> /bin/bash

# View logs.
$ docker-compose logs

# List/remove network.
$ docker network [ ls | rm <network_name> ]

# List/remove volumes.
$ docker volume [ ls | rm <volume_name> ]

# Stop containers.
$ docker-compose stop

# Stop and remove containers. Any data which is not in a volume will be lost.
$ docker-compose down

PHP

Choose a different version of php

By default docker-compose.yml uses the latest tag name of the php image which corresponds to php 7.1.

services:
  php:
    image: ${PROJECT_NAMESPACE}/${REPOSITORY_NAME}-php:latest

If you want a specific version of php, you can change it with one of those values: 5.6, 7.0 or 7.1. Example:

  php:
    image: ${PROJECT_NAMESPACE}/${REPOSITORY_NAME}-php:5.6

The default docker repository already provides the images for those php version. Otherwise you need to build them by yourself with:

$ ./bin/build

Add PHPMyAdmin

Edit docker-compose.yml and add a new service definition:

services:
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    ports:
     - "8080:80"
    environment:
      PMA_HOST: mysql
    networks:
      - backend

Then phpmyadmin will be accessible to http://localhost:8080/

Composer basic usage

Place the composer.json file that describes the dependencies of your project inside the app folder, then install the defined dependencies through the php container:

$ docker-compose run --rm php composer install

Create a new Symfony project

You can use Composer to ease the creation of a new symfony project:

$ rm -rf app/* && docker-compose run --rm -u $(id -u):$(id -g) php composer create-project symfony/framework-standard-edition .

As from Symfony3.2 you can use the environment variables into you service container configuration, using the %env(MYSQL_DATABASE)% notation:

Symfony config

Composer will create a new Symfony Standard Edition application under the app/ directory.

A minimum configuration file to get your application running under Nginx is already provided from docker-skeleton-php. Remove the default.conf file and rename symfony.conf.example into symfony.conf:

$ rm sites/default.conf
$ mv sites/symfony.conf.example sites/symfony.conf

Now remove the access check from app/web/app_dev.php:

// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']) || php_sapi_name() === 'cli-server')
) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

Warning: After you deploy to production, make sure that you cannot access the app_dev.php

You can start the containers now:

$ docker-compose up -d

Symfony console

How can I use Symfony's console?

  • For Symfony 3:

    $ docker-compose run --rm php php bin/console
  • For Symfony 2:

    $ docker-compose run --rm php php app/console

Desplegando Symfony

Desde el contenedor PHP:

docker-compose exec php bash

Ejecutar

composer install
[Configurar parameters.yml]
php app/console doctrine:schema:update --force
php app/console cache:clear
php app/console fos:user:create --super-admin

Instalando node y uglifycss / uglifyjs

Desde el contenedor PHP:

docker-compose exec php bash

Ejecutar

NODE:
# La ruta node será /usr/bin/nodejs

curl -sL https://deb.nodesource.com/setup_6.x | bash
apt-get install -y nodejs

npm install uglify-js2 -g
# La ruta uglifyj2: /usr/lib/node_modules/uglify-js2/bin/uglifyjs2

npm install uglifycss -g
# La ruta uglifycss: /usr/lib/node_modules/uglifycss/uglifycss

Instalando wkhtmltopdf

apt-get install wkhtmltopdf
apt-get install xvfb

About

curso-intensivo con docker

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published