Install Composer with Docker

As a memo so that it will be useful when you touch Docker in the future.

Whether to use RUN or COPY in Dockerfile

You can do it from the official Composer page, but composer official


FROM php:x.xx-fpm

RUN php -r "copy('', 'composer-setup.php');" && \
    php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
    php composer-setup.php
    php -r "unlink('composer-setup.php');"

This seems to have a problem like changing the Dockerfile every time the version is upgraded due to the hash value on the second line.

Better to use COPY


FROM php:x.xx-fpm

COPY COPY --from=composer /usr/bin/composer /usr/bin/composer

All you have to do is write this. When you want to specify the version of composer

xx.x /usr/bin/composer /usr/bin/composer

You can do it.

By the way


If is specified, installation as root is permitted.

Recommended Posts

Install Composer with Docker
Install java with Ubuntu 16.04 based Docker
composer install error
Install Docker Desktop for Mac with Homebrew
Install Docker with WSL2 Memo ([Part 2] Docker introduction)
Dealing with composer installation errors in Docker
Install java with Homebrew
Install Java with Ansible
Install OpenJDK8 with RPM
Rails deploy with Docker
Run Pico with docker
Explode Docker with WSL2
Install Docker on Manjaro
Use Puphpeteer with Docker
I couldn't install docker with raspberry pi2 b +.
Install Gradle with ubuntu16.04
How to install Docker
Operate Emby with Docker
Use ngrok with Docker
Run Payara with Docker
Php settings with Docker
Getting Started with Docker
Disposable PHP with Docker
Bundle install with docker + rails6 does not reflect gem
Use GDAL with Python with Docker
Install Docker on Raspberry Pi
Clogged with Express npm install
Install Docker on Windows 10 PRO
Network install CentOS 8 with Kickstart.
Install Java 7 with Homebrew (cask)
Deploy with EC2 / Docker / Laravel
Run TAO Core with Docker
Install Docker on Ubuntu Server 20.04
Docker management with VS Code
Install Oracle JDK 8 with Ansible
Install yarn in docker image
Set up GitLab with docker
Get started with DynamoDB with docker
Docker autostart settings with wsl2
[Docker] Rails 5.2 environment construction with docker
Spring Boot starting with Docker
Build docker environment with WSL
Version control CocoaPods with Docker
Install docker on AWS EC2
Web application built with docker (1)
Install docker, docker-compose for debin10
I tried BIND with Docker
React environment construction with Docker
Build DynamoDB local with Docker
[Docker] Use whenever with Docker + Rails
Using PlantUml with Honkit [Docker]
[PHP8] Install and use PECL YAML function (YAML parser) with Docker
Rails + MySQL environment construction with Docker
Install openjdk8 on Docker image (Debian)
Install Ruby on MSYS2 with pacman
Install Amazon Corretto JDK with SDKMAN!
Install Docker on AWS Ubunt 20.04 LTS
Node.js environment construction with Docker Compose
Run lambda with custom docker image
Deploy a Docker application with Greengrass
Build Couchbase local environment with Docker