Originally published on adithya.dev
I have been building packages for my private use and came across this problem where I had to build a package and integrate it into a project that's running on Docker.
For local development, I make use of repositories
in composer.json to achieve this. In Docker, since your host machine and docker images run separately, you cannot include the path as you would, if you ran it on the same machine (without Docker).
Tools used are
- https://github.com/spatie/package-skeleton-laravel
- Dockerfile (I'm using https://github.com/aschmelyun/docker-compose-laravel)
//composer.json
"require": {
"adithya/package-name": "dev-master"
},
"repositories": [
{
"type": "path",
"url": "../package-name"
}
]
When I ran composer install
, I got the following error
[RuntimeException]
Theurl
supplied for the path (../package-name) repository does not exist
After a bit of researching, I found the solution. In your docker-compose.yml
, add the absolute path to your package and a mount point under your volumes
in composer
image.
composer:
build:
context: .
dockerfile: composer.dockerfile
container_name: composer
volumes:
- ./src:/var/www/html
- /usr/Code/package-name:/package-name
working_dir: /var/www/html
depends_on:
- php
user: laravel
networks:
- laravel
entrypoint: ['composer']
Similarly, make sure to add the volume to your php container!
Now on your Project where you want to include the package, change the reference for your URL
//composer.json
"require": {
"adithya/package-name": "dev-master"
},
"repositories": [
{
"type": "path",
"url": "/package-name"
}
]
Docker should automatically mirror the changes in your package to the project so it should be a breeze. If you do choose to use ADD
in your dockerfile instead of mounting the volumes, your changes won't be automatically reflected since it copies your folder at the build time.
ADD . /package-name
Top comments (0)