0

I'm running Rundeck with docker-compose and Dockerfile and i need to modify a value inside a file which is inside the container.

I can copy the modified file from another place (local) and place it inside the container while the build phase is in process but somehow the file gets replaced by the original one and that approach doesn't work.

I've also tried to run SED command (so i can modify the exact line of the file) inside Dockerfile but again that doesn't work and the container shows the original file with nothing modified inside.

So, I know that the image is inn mutable and cannot be modified (also is not a good practice).

What can I do here?. What is the best approach to every time I run a new Rundeck image apply that modification I need within the file?.

Replication escenario: Dockerfile

FROM rundeck/rundeck:4.2.3-rc1-20220712    
WORKDIR /home/rundeck    
RUN sudo apt-get update
RUN sudo apt-get install nano

Docker-compose (be aware of yml format!)

version: '3.4'
services:
rundeck:
    restart: always
    build: .
    container_name: rundeck
    links:
      - mysql
    tty: true
    ports:
      - 4444:4440
    environment:
        RUNDECK_GRAILS_URL: http://192.168.1.5:4444
        RUNDECK_SERVER_FORWARDED: 'true'
        RUNDECK_DATABASE_DRIVER: org.mariadb.jdbc.Driver
        RUNDECK_DATABASE_USERNAME: rundeck
        RUNDECK_DATABASE_PASSWORD: rundeck
        RUNDECK_LOGLEVEL_DEFAULT: info
        RUNDECK_DATABASE_URL: jdbc:mysql://mysql/rundeck?autoReconnect=true&useSSL=false             
    volumes:
      -  /run/docker.sock:/var/run/docker.sock
      -  /home/ubuntu/.ssh:/home/rundeck/.ssh
      - ./rundeck_data:/home/rundeck/server/data
      - ./rundeck_config:/home/rundeck/server/config

Once the container is up, look up the file located at /home/rundeck/server/config "rundeck-config.properties" inside the container. On line 42 i need to change value 30d (actual) by 0d.

Any help will be really appreciated!.

larsks
  • 41,276
  • 13
  • 117
  • 170
  • Also posted on https://forums.docker.com/t/docker-run-sed-command-before-container-starts/128231 – Arjan Aug 25 '22 at 22:02

1 Answers1

1

You don't need to run sed before the container starts.

If you read through the documentation for the rundeck docker image, it says that:

Remco is used to generate the Rundeck configuration files from templates. It supports different key/value sources such as vault, etcd, and dynamodb. All configuration backends are combined into a unified keyspace. This allows storing parts of the configuration space in different backends. The default configuration uses environment variables.

This suggests we can achieve your desired configuration using environment variables, and indeed, if we set RUNDECK_API_TOKENS_DURATION_MAX to 0d...

version: '3.4'
services:
  mysql:
    image: docker.io/mariadb:10
    environment:
      MARIADB_ROOT_PASSWORD: secret
      MARIADB_DATABASE: rundeck
      MARIADB_USER: rundeck
      MARIADB_PASSWORD: rundeck

  rundeck:
    restart: on-failure
    build: .
    container_name: rundeck
    ports:
      - 4444:4440
    environment:
      RUNDECK_GRAILS_URL: http://localhost:4444
      RUNDECK_SERVER_FORWARDED: 'true'
      RUNDECK_DATABASE_DRIVER: org.mariadb.jdbc.Driver
      RUNDECK_DATABASE_USERNAME: rundeck
      RUNDECK_DATABASE_PASSWORD: rundeck
      RUNDECK_LOGLEVEL_DEFAULT: info
      RUNDECK_DATABASE_URL: jdbc:mysql://mysql/rundeck?autoReconnect=true&useSSL=false
      RUNDECK_API_TOKENS_DURATION_MAX: 0d
    volumes:
      - rundeck_data:/home/rundeck/server/data
      - rundeck_config:/home/rundeck/server/config

volumes:
  rundeck_data:
  rundeck_config:

Then the result rundeck-config.properties contains:

rundeck@f9b1ceaaff8e:~$ grep tokens.duration.max server/config/rundeck-config.properties
rundeck.api.tokens.duration.max=0d

In the container, you can find the template sources in /etc/remco/templates. I was able to determine the correct environment variable name by inspecting /etc/remco/templates/rundeck-config.properties, which contains:

rundeck.api.tokens.duration.max={{ getv("/rundeck/api/tokens/duration/max", "30d") }}

In the above example docker-compose.yaml file, note also that I've removed the links entry, which has been deprecated for quite a while. Your containers can refer to other containers in the same compose file by name without the use of links.

larsks
  • 41,276
  • 13
  • 117
  • 170