0

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
  • Can you not just add an entrypoint tag to docker-compose that spawns the entrypoint process and then executes the script. This is not best practice I know but maybe an option none the less. – Raman Sailopal Oct 27 '22 at 09:58
  • Since you're already bind-mounting the Docker socket into Jenkins, can you use [Jenkins's native Docker support](https://www.jenkins.io/doc/book/pipeline/docker/) to build your application inside a `php` container? That would avoid this particular problem, and it would be more flexible if you did ever need to change the language runtime version; you could update it in an individual application's `Jenkinsfile` without rebuilding your CI system. – David Maze Oct 27 '22 at 10:23
  • @RamanSailopal When I tried this only my script was executed and the container wasn't started, because it overrode the default command. – ricklepick Oct 28 '22 at 08:35
  • @DavidMaze thank you will try this out. Your approach sounds more appropriate to solve this! – ricklepick Oct 28 '22 at 08:35

0 Answers0