I want to start my docker container with a docker-compose command. The underlying docker image CMD should just be executed regularly, and I want to append my script at some point.
When reading about executing shell commands in docker, entrypoint is brought up. But according to the documentation start of the image + appended script without overriding entrypoint or cmd is not possible through entrypoint (https://docs.docker.com/compose/compose-file/#entrypoint):
Compose implementations MUST clear out any default command on the Docker image - both ENTRYPOINT and CMD instruction in the Dockerfile - when entrypoint is configured by a Compose file.
A similar question was asked here, but the answer did not address the issue: docker-compose, how to run bash commands after container has started, without overriding the CMD or ENTRYPOINT in the image docker is pulling in?
Another option would be to copy & edit the dockerfile of the pulled image, but that would not be great for future imports: docker-compose: run a command without overriding anything
What I actually want to do, is coupling the install of php & composer to the docker-compose up process.
Here is my docker-compose file:
version: '3.8'
services:
jenkins:
image: jenkins/jenkins:2.361.1
restart: always
privileged: true
user: root
ports:
- "8080:8080"
- "50000:50000"
container_name: "aaa-jenkins"
volumes:
- "./jenkins_configuration:/var/jenkins_home"
- "/var/run/docker.sock:/var/run/docker.sock"
- "/usr/bin/docker:/usr/bin/docker"
My script looks something like this:
#!/bin/bash
apt update
apt -y install php
apt -y install php-xml php-zip php-curl php-mbstring php-xdebug
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
composer