12/08/2018, 15:17

In Action Tutorial Series - Docker - PHP Development with Docker

A.1. Brief explanation A.1.1. Image Image is a package which includes code, a runtime, libraries, environment variables, and config files (Dockerfile). Get from http://hub.docker.com Types: By source: offical and public/user image By level: scratch, base os and application image A.1.2. ...

A.1. Brief explanation

A.1.1. Image

Image is a package which includes code, a runtime, libraries, environment variables, and config files (Dockerfile). Get from http://hub.docker.com Types:

  • By source: offical and public/user image
  • By level: scratch, base os and application image

A.1.2. Container

Container is a running instance of a image. It is isolated from host env, only accessing host files and ports if configured

A.1.3. Docker compose

Docker compose is a tool for managing many docker container in a central config file (docker-compose.yml)

A.2. Installing

Install docker

To install AUFS storage driver. Others drivers: Btrts, Device mapper, VFS, ZFS

$ apt-get install 
    linux-image-extra-$(uname -r) 
    linux-image-extra-virtual
    $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

Add docker repository

$ add-apt-repository 
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu 
   $(lsb_release -cs) 
   stable"

Install docker ce

$ apt-get install docker-ce

Check

$ docker -v
// Docker version 17.03.1-ce, build c6d412e

Install docker-compose

Get binary

$ curl -L https://github.com/docker/compose/releases/download/1.12.0/docker-compose-`uname -s`-`uname -m` >  ~/docker-compose

Move to bin folder

 $ sudo mv ~/docker-compose /usr/local/bin/docker-compose

Make it executable

$ sudo chmod +x /usr/local/bin/docker-compose

Check

$ docker-compose --version
$ #docker-compose version 1.13.0, build 1719ceb

First hello world application

Create helloworld folder

mkdir ~/test && cd ~/test

Create example index.php file

echo "<?php echo 'Welcome to docker'; ?>" > index.php

Create Dockerfile

touch Dockerfile

Add following lines to Dockerfile

# Set base application image.
FROM php:7.0-cli

# Set working dir in container environment
WORKDIR /app

# Add all current files and folder on host env to container env
ADD . /app
# Alternative: COPY . /app

# Run command `php index.php` in container env
CMD ["php", "index.php"]
# Alternative: CMD php index.php

Build up image

docker build -t helloworld ./
# -t helloworld: set helloworld as image name
# ./ : context to build image. ./ mean current directory

Running container use helloworld image

docker run helloword

If you see "Welcome to docker" you're ready to go             </div>
            
            <div class=

0