Reputation: 1730
I know about the laradock, but i need to pass all the steps for myself.
i gonna learn Laravel and the same time recently i have opened for myself docker :)
now i need to join alltogether:
docker-compose with images:
- php:7.2.2-apache
- mariadb
- phpmyadmin/phpmyadmin
- and some how composer
laravel will be on my host outside containers.
so far i have made my own image "web_server" from the php:7.2.2-apache image and run inside mod_rewrite
FROM php:7.2.2-apache
RUN apt update && apt install mc -y && apt install composer -y
RUN a2enmod rewrite
my docker-compose.yml
looks like
version: '3'
services:
db:
image: mariadb
volumes:
- ./db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: "secretpswd"
MYSQL_DATABASE: "test_db"
MYSQL_USER: "my_user"
MYSQL_PASSWORD: "secretpswd"
ports:
- "3306:3306"
web:
image: web_server
container_name: php_web
depends_on:
- db
volumes:
- ./www:/var/www/html/
ports:
- "80:80"
stdin_open: true
tty: true
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: pma
depends_on:
- web
- db
environment:
PMA_HOST: "db"
PMA_PORT: 3306
PMA_ARBITRARY: 1
restart: always
ports:
- 8080:80
volumes:
- ./sessions:/sessions
now i have to install composer ...
i have two choices
composer/composer
image from the docker hub in this case i
have no idea how it will be used by laravel and with laravel
because laravel will be under the control of separate web
containerweb_server
image which is made fromphp:7.2.2-apache
imagei have tried but start receiving errors
The following packages have unmet dependencies:
composer : Depends: php-symfony-console (>= 2.5) but it is not installable
Depends: php-symfony-filesystem (>= 2.5) but it is not installable
Depends: php-symfony-finder (>= 2.4) but it is not installable
Depends: php-symfony-process (>= 2.4) but it is not installable
Depends: php-cli
Depends: php-common but it is not installable
Depends: php-json-schema but it is not installable
Depends: php-composer-ca-bundle (>= 1.0) but it is not installable
Depends: php-composer-ca-bundle (< 2~~) but it is not installable
Depends: php-composer-semver (>= 1.0) but it is not installable
Depends: php-composer-semver (< 2~~) but it is not installable
Depends: php-composer-spdx-licenses (>= 1.0) but it is not installable
Depends: php-composer-spdx-licenses (< 2~~) but it is not installable
Depends: jsonlint (>= 1.4) but it is not going to be installed
Depends: jsonlint (< 2~~) but it is not going to be installed
Depends: php-cli-prompt (>= 1.0) but it is not installable
Depends: php-cli-prompt (< 2~~) but it is not installable
Depends: php-psr-log (>= 1.0) but it is not installable
Depends: php-psr-log (< 2~~) but it is not installable
Recommends: git but it is not going to be installed E: Unable to correct problems, you have held broken packages. The command '/bin/sh -c apt update && apt install mc -y && apt install composer -y' returned a non-zero code: 100
so it's time to ask for help.
which way should i use?
in case of separate composer/composer
container how to use it
inside web_server container and how laravel will use it
php:7.2.2-apache
image
how to solve those errorsUpvotes: 1
Views: 2025
Reputation: 291
I think best option is to make a separate docker container for composer. so that you don't have composer mixed with your php apache container.
you can add the following lines to your docker-compose file:
composer:
restart: 'no'
container_name:composer
image: composer:latest
working_dir: /var/www/html
command: composer install -d /var/www/html
volumes:
- ./www:/var/www/html/
the volume is being synced in the composer container and in your php container so the vendor folder will also be synced between the two containers.
the restart: no
option is there so that when you run docker-compose up
the composer container is only being started once, when it is done it is being stopped.
To run composer install you can use: docker-compose run composer composer install
You can also use the command on the next line, so that composer install is a little bit faster.
(more information about the package: https://github.com/hirak/prestissimo)
command: >
bash -c "composer global require hirak/prestissimo && composer install -d /var/www/html"
Upvotes: 2