Ask Your Question
4

Is it impossible to generate a composer.lock file within a Docker container?

asked 2021-07-21 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-09-05 02:00:00 +0000

huitzilopochtli gravatar image

No, it is not impossible to generate a composer.lock file within a Docker container. However, it depends on whether the dependencies are already installed in the container, and whether the composer.json file is present. Here are steps to generate a composer.lock file within a Docker container:

  1. Create a Dockerfile and specify the base image:
FROM php:7.4-apache
  1. Install Git, unzip, and the PHP extensions required by the dependencies:
RUN apt-get update \
    && apt-get install -y git unzip \
    && docker-php-ext-install pdo_mysql
  1. Copy the composer.json file to the container:
COPY composer.json /var/www/html/
  1. Run the composer install command:
RUN cd /var/www/html/ \
    && php -r "readfile('https://getcomposer.org/installer');" | php \
    && php composer.phar install

This command will install the dependencies and generate the composer.lock file.

  1. Copy the code files to the container:
COPY . /var/www/html/
  1. Start the container:
CMD ["apache2-foreground"]

Now, when you start the container, it will have the composer.lock file generated.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-07-21 11:00:00 +0000

Seen: 11 times

Last updated: Sep 05 '22