#duh! Pick the base image (this is latest as of May 2020)
FROM php:7.4.5-apache
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
#duh!
RUN apt-get update
#Install zip+icu dev libs
RUN apt-get install libzip-dev zip libicu-dev -y
#Install PHP extensions zip and intl (intl requires to be configured)
RUN docker-php-ext-install zip && docker-php-ext-configure intl && docker-php-ext-install intl
#Required for htaccess rewrite rules
RUN a2enmod rewrite
-
-
Save jdecode/69f51cc0680de7c885770cbef65ba254 to your computer and use it in GitHub Desktop.
Once built, run the docker image using the tag that have given e.g. cakephp:0.1
in the previous comment.
docker run cakephp:0.1
You can check if the docker image is running by running
docker ps
You should see something like the screenshot (I used the tag "jdecode/cakephp:0.2")
The name at the end is generated automatically (if you don't send it as a parameter - I don't remember the flag for that now, and too lazy to Google it).
You can use this name to SSH using the following command (the container name is beautiful_jang
from the screenshot)
docker exec -it beautiful_jang /bin/bash
You can also use the container ID (from docker ps
) e.g.
docker exec -it 5c72b52eb593 /bin/bash
Interestingly, I tried it for Laravel, and it worked pretty much in a similar way:
#duh! Pick the base image (this is latest as of May 2020)
FROM php:7.4.5-apache
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
#duh!
RUN apt-get update
#Install zip+icu dev libs
RUN apt-get install libzip-dev zip libicu-dev -y
#Install PHP extensions zip and intl (intl requires to be configured)
#RUN docker-php-ext-install zip && docker-php-ext-configure intl && docker-php-ext-install intl
WORKDIR /var/www/html
RUN composer create-project --prefer-dist laravel/laravel .
Eventually, after some playing around, I now have 2 set of Dockerfile
and docker-compose.yml
- CakePHP and Laravel, both have MySQL, Postgres and Redis (php-redis extension is not installed yet).
Depending on the need, make changes in the docker-compose.yml
file's DATABASE_URL
value.
CakePHP
Dockerfile
content:
FROM jdecode/cake406-mysql8:0.2
(yes, that is it)
docker-compose.yml
(this is a long file, yes)
version: "3"
services:
cake:
build:
context: .
dockerfile: Dockerfile
image: cakephp:0.x
ports:
- 8080:80
links:
- mysql
- pgsql
- redis
depends_on:
- mysql
- pgsql
- redis
environment:
DATABASE_URL: mysql://root:[email protected]/cake
#DATABASE_URL: postgres://postgres:[email protected]/cake
DEBUG: 'true'
SECURITY_SALT: 49e558df8e733a6daedbe054a9ccd7add9d9a6efa8a96cf3248815c364b47391
networks:
cake_net:
ipv4_address: 172.43.1.1
mysql:
image: mysql:latest
ports:
- 3306:33060
volumes:
- mysql_data:/var/lib/mysql
restart: always
container_name: cake-mysql
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: mysqldocker
MYSQL_DATABASE: cake
networks:
cake_net:
ipv4_address: 172.43.1.2
pgsql:
image: postgres:latest
ports:
- 5432:54320
volumes:
- pgsql_data:/var/lib/postgres
container_name: cake-pgsql
environment:
POSTGRES_PASSWORD: pgsqldocker
POSTGRES_DB: cake
networks:
cake_net:
ipv4_address: 172.43.1.3
redis:
image: redis:latest
restart: always
container_name: cake-redis
ports:
- 6379:63790
networks:
cake_net:
ipv4_address: 172.43.1.4
volumes:
mysql_data: {}
pgsql_data: {}
redis_data: {}
networks:
cake_net:
ipam:
driver: default
config:
- subnet: 172.43.0.0/16
Laravel
Dockerfile
content
FROM jdecode/laravelphp:0.3
(Yes, I got lazy with naming, or rather this is neat)
docker-compose.yml
content
version: "3"
services:
laravel:
build:
context: .
dockerfile: Dockerfile
image: laravelphp:0.x
ports:
- 8080:80
links:
- mysql
- redis
depends_on:
- mysql
- redis
environment:
#DATABASE_URL: mysql://root:[email protected]/laravel
DATABASE_URL: postgres://postgres:[email protected]/laravel
networks:
laravel_net:
ipv4_address: 172.53.1.1
mysql:
image: mysql:latest
#image: mysql:5.7.24
ports:
- 3306:33060
volumes:
- mysql_data:/var/lib/mysql
restart: always
container_name: laravel-mysql
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: mysqldocker
MYSQL_DATABASE: laravel
networks:
laravel_net:
ipv4_address: 172.53.1.2
pgsql:
image: postgres:latest
ports:
- 5432:54320
volumes:
- pgsql_data:/var/lib/postgres
container_name: laravel-pgsql
environment:
POSTGRES_PASSWORD: pgsqldocker
POSTGRES_DB: laravel
networks:
laravel_net:
ipv4_address: 172.53.1.3
redis:
image: redis:latest
restart: always
container_name: laravel-redis
ports:
- 6379:63790
networks:
laravel_net:
ipv4_address: 172.53.1.4
volumes:
mysql_data: {}
pgsql_data: {}
redis_data: {}
networks:
laravel_net:
ipam:
driver: default
config:
- subnet: 172.53.0.0/16
Instructions to use above Dockerfile and docker-compose.yml files.
Place these in a folder, and go to Ubuntu 19.10 CLI (not tested anywhere else, yet) and enter:
docker-compose up --build
For CakePHP, go to 172.43.1.1
For Laravel, go to 172.53.1.1
Switched to Ubuntu 20.04 and docker login
was failing.
Google/GitHub gave the solution - sudo apt install golang-docker-credential-helpers
docker-compose run kode bin/cake migrations migrate
docker-compose run kode bin/cake migrations seed
Build the docker image the above Dockerfile using
docker build -t "cakephp:1" .
Give any tag - the text in double quotes in the command above - I would give it something like this for local development, and if I need to push it to docker-hub, then I will usually prefix with my docker-hub username "jdecode".
docker build -t "jdecode/cakephp:0.1" .
This looks more like it ;)
Optionally, I would push to docker-hub if I feel like using
docker push jdecode/cakephp:0.1
(or whatever name/tag I would be using)