Skip to content

Instantly share code, notes, and snippets.

@ivanvermeyen
Last active Dec 19, 2018
Embed
What would you like to do?
Docker Project Setup with Vessel

Docker Project Setup with Vessel

For an in-depth Docker tutorial, see https://course.shippingdocker.com/

Install

Install docker on MacOS/Windows:

Install docker in project:

https://github.com/shipping-docker/vessel

composer require shipping-docker/vessel
php artisan vendor:publish --provider="Vessel\VesselServiceProvider"
bash vessel init

For non-Laravel apps: the service provider just copies the files and subdirectories of the docker-files folder to your project (https://github.com/shipping-docker/vessel/tree/master/docker-files).

Edit .env :

APP_ENV=local
APP_PORT=8080
MYSQL_PORT=33060
DB_DATABASE=dbname
DB_USERNAME=root
DB_PASSWORD=root

PHP version

Edit docker-compose.yml and add a tag to the app image so you store separate images:

image: vessel/app:php-7.x

Next edit the files in docker/app to use the PHP version. Or copy any backup configuration…

Install PHP extensions and other stuff via docker/app/Dockerfile

MySQL root user

If you don’t need an additional user except root, comment out these lines in the mysql section of docker-compose.yml. Reason: if DB_USERNAME is root, the container won't be started properly.

#MYSQL_USER: "${DB_USERNAME}"
#MYSQL_PASSWORD: "${DB_PASSWORD}"

Run

./vessel start

Edit PHP.ini

See the server’s ini file:

./vessel exec app php -—ini

Copy the ini files to the shared root folder:

./vessel exec app cp /etc/php/7.1/fpm/php.ini /var/www/html
./vessel exec app cp /etc/php/7.1/cli/php.ini /var/www/html

Move the files to ./docker/app/php/ or somewhere...

Then edit the docker-compose.yml file and add a volume to app:

volumes:
 - .:/var/www/html
 - ./docker/app/php/fpm/php.ini:/etc/php/7.1/fpm/php.ini
 - ./docker/app/php/cli/php.ini:/etc/php/7.1/cli/php.ini

Then stop and start the containers (not restart):

./vessel stop
./vessel start

From now on, if you now make changes to the ini file, just restart:

./vessel restart

Rebuild

Stop containers and remove the app image (specify tag if needed):

./vessel stop && docker image rm vessel/app:php-7.1

To also remove database data, get the volume name and remove it:

docker volume ls
docker volume rm volume_name

Start and build:

./vessel start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment