Create new docker container with composer 2.0 installed - php

I am very new to docker and laradock, but I am trying to figure out how to create a new container that comes with composer 2.0 (or latest) installed automatically? How do I tell Laradock that I want the latest composer upon build/creation of the container?
I have followed several tutorials and several posts about this type of situation...however, nothing has panned out. If I build the container, and start the workspace bash, it comes up with composer 1.10 every time. I can update it from within the container, but I would prefer to have it installed by default, when the container is created. Thanks in advance.

You have a few options. Two that spring to mind are:
You can use the RUN command in your docker file to run pretty much any commands
you like. So you could in theory install composer this way.
You can manually install composer and then build a new image. The new image will contain the composer install. You then push that to your repo of choice and use it as the base image in your dockerfile. This is quite common practice.

Related

How to cache composer packges in Jenkins

I've got a Laravel project and simple pipeline in Jenkins which build Docker image from Dockerfile, pull code in it and execute composer install. Everything working fine so far, but installing composer packages takes a lot of time (like 6-7 minutes). I've tried to persist vendor directory somewhere, create symlink to it or something but nothing worked so far. I wonder if there is some better more official way to handle that? Anyone has some idea or experience in it? Or maybe some different CI tool?
Ok, I ended up with two solutions:
I mounted composer cache directory to some directory in host to speed up composer packages installing:
dockerfile {
filename 'Dockerfile'
args '-v $HOME/composer_cache:/.composer/cache'
}
There is (not so obvious, because Jenkins panel is little messy) option to disable workspace clean up before/after code checkout. One can delete those steps in pipeline configuration under "Branch Sources" section (with red X above those "Behaviours").

Does composer have an official docker image?

I've been running composer install in a shell script when I build a docker image, but that along with a lot of other calls is making my build super slow and I'm wondering if there's a better/different way to go about this.
As #janshair-khan points out, there are two images. But composer/composer is deprecated, as you can see from the source repository. So I suggest you use the Docker Official Image for composer.

Issue with laravel composer

(don,t get angry with that)why we use composer i searched in google it says it is used for the dependencies of laravel, but why we create project in composer?cant we create it in simply in xampp/htdocs/laravel/... there as in past they does in codeigniter?explain it simply and clearly, what is the purpose of using the artisan commands, like php artisan serve that create a host address like localhost:8000 cant we go there in browser simply like localhost/laravelproject?and does composer works offline,without internet access,i mean entering those commands in cmd prompt?simply my concept is not clear with using composer with laravel, clear my concept...thanks
As google said, composer is always for dependencies, not just laravel but in any other framework or libraries, composer is used to automatically download dependencies needed for code to work.
Laravel is based on some packages that are some kind of third-party packages. When you create a project in codeigniter you copy all files needed for project. You can do this in laravel too, but you should have all files that are needed. Now you can download all files manually or just set those files and libraries in a file named composer and let composer do that for you. And even if there are dependencies for libraries that you mention for composer, composer detects them and downloads them too.
When you create laravel project with composer, you can save all files and use them for another project (as I did), and not to use composer again.
Artisan commands are just here to help you. Many of commands that are supported by artisan, are possible to be done by your hand, but artisan is here to help you.
Of course you can use xamp or wamp to host your laravel project, here serve command is another option to serve your project. You do not have to use it (as I never do).
Composer does not have dependencies and it just detects dependencies and downloads them.
Hope that helps.

How to Deploy a Cake PHP App

I wonder if someone can help me. I've been handed in a Cake PHP app that I need to 1) add minor changes 2) deploy. I've never really worked with Cake before and was wondering whether do I need to anything in order for it to work?
For instance, With a Node app, you need to install modules npm install. With a Rails app you'll likely need to install the gems bundle install.
Is there something similar with Cake? I've set the localhost server, but when I try to access the url I get all sort of errors. Some I've fixed (missing environment settings which I just override the Redis host and port). The latest one is:
{
"exception":{
"class":"MissingControllerException",
"code":404,
"message":"Controller class Controller could not be found.",
"file":"\/Library\/WebServer\/Documents\/php\/oompbe\/vendors\/cakephp\/lib\/Cake\/Routing\/Dispatcher.php",
"line":154,
"trace":[
"#0 \.../app\/webroot\/index.php(109): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))",
"#1 {main}"
]
}
}
PS: What's up with all the crazy \/\/?
PPS: Can I find out the version Cake I'm running?
CakePHP is just php. As most properly done php apps these days it comes with composer. I recommend you to read at least the basics of it's manual. Composer is an awesome tool.
git clone <repo>
cd <reponame>
composer install
If you start a new Cake application the official documentation tells you how to this as well:
composer create-project --prefer-dist cakephp/app [app_name]
If you want to automate things further composer provides you callback scripts. They'll allow you to automate tasks, basically trigger commands, after different actions. This is pretty useful to build assets after a composer update for example. I recommend you to not put lots of commands into that section but instead have dedicated script files you trigger by the callbacks.
Can I find out the version Cake I'm running?
If installed via composer it is usually in vendor/cakephp/cakephp/version.txt. Check the content of that file.

PHP Composer dependency of library

I'm developing a PHP-App using composer.
Now I need a PHP-Libary, which is also developed by me.
Inside the IDE there is no problem using the library-classes. But when the app is running inside Apache2 I need to install the library via "composer update".
But when I change some library-class I always need to reinstall the new code via composer. Before that I have to push my changes to the SCM.
Is there a way to simplify this process during development?
After trying out symlinks, the solution for me is symlinking the dependend library with ln -s TARGET NAME. Adding the dependency to composer.json is for generating the classmaps and running without errors after deleting the symlink. It works fine. Also a "composer update" is working without overriding the symlink. New classes are found immedeately without doing the whole process described in the question.

Categories