Deployed the environment for the site through docker-compose . The site is on laravel and it needs to perform a composer install , but the execution of this command says that I have an old version of php . It turns out that you need to install the composer in a container? Maybe there are other solutions?

Docker-compose.yml file

 version: '2' services: nginx: image: evild/alpine-nginx:1.9.15-openssl container_name: lemp_nginx restart: always links: - php volumes: - ./project:/var/www/ - ./docker/nginx/conf/nginx.conf:/etc/nginx/conf/nginx.conf:ro - ./docker/nginx/conf.d:/etc/nginx/conf.d:ro ports: - 8080:80 - 443:443 php: image: evild/alpine-php:7.0.6 working_dir: /var/www container_name: lemp_php restart: always volumes: - ./project:/var/www/ depends_on: - db links: - db environment: - DB_NAME=mysql - DB_USER=root - DB_PASSWORD=password db: image: mariadb:latest container_name: lemp_mariadb restart: always volumes: - db-data:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=password volumes: db-data: driver: local 
  • and how do you run composer ? - Mikhail Vaysman
  • I run it outside of the container - ruslik
  • I understand that it needs to be run inside the container, but inside the php container I do not have composer - ruslik
  • one
    you understand correctly. You can assume that the container is another computer (virtual machine). - Mikhail Vaysman
  • one
    Update your question according to the guidelines for keeping discussions on Stack Overflow , instead of posting comments. - Mikhail Vaysman

1 answer 1

This is done like this:

  1. Define container name or id

     docker ps 
  2. Log into the container. The shell is usually bash.

     docker exec -it <имя или id контейнера> <shell> 
  3. Inside the container, execute the commands you need. In your case install composer

     php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');" 

NB

These changes will disappear after container restart. If you want them to stay, then you need to create a new version of the container and use it in docker-compose.yml .

  • Describe the second option pzhl, you need to install the composer once and the command can always run - ruslik
  • Ask a new question and attach a Dockerfile to it. - Mikhail Vaysman
  • Sorry, but I’m a docker in the docker questions, what dockefile do you mean by docker-compose.yml? - ruslik
  • attach docker-compose.yml and I will say what else you need to do. - Mikhail Vaysman
  • Added file description - ruslik