2

I'm running docker-letsencrypt through a docker-compose.yml file. It comes with PHP. I'm trying to run PHP composer with it. I can install composer while being in the container through bash, but that won't stick when I recreate the container. How do I keep a permanent install of composer in an existing container that doesn't come with compose by default?

My docker-compose.yml looks like this:

version: "3"
services:

  letsencrypt:
    image: linuxserver/letsencrypt
    container_name: letsencrypt
    cap_add:
      - NET_ADMIN
    ports:
      - "80:80"
      - "443:443"
    environment:
      - PUID=1000
      - PGID=1000
      - EMAIL=<mailadress>
      - URL=<tld>
      - SUBDOMAINS=<subdomains>
      - VALIDATION=http
      - TZ=Europe/Paris
    volumes:
      - /home/ubuntu/letsencrypt:/config

I did find the one-line installer for composer:

php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer

I could add this to command in my docker-compose.yml, but that would reinstall composer even on container restarts right?

1 Answer 1

3

You're right about your comment about the command option, it will indeed be run every time you launch your container.

One workaround would be to create your own dockerfile, as follow :

FROM linuxserver/letsencrypt
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer

(RUN directives are only run during the build step).

You should then modify your docker-compose.yml :

...
build: ./dir
  #dir/ is the folder where your Dockerfile resides
  #use the dockerfile directive if you use a non-default naming convention
  #or if your Dockerfile isn't at the root of your project 
container_name: letsencrypt
  ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.