rails credentials inside of docker is no longer opening

My rails environment runs from a Docker. Previously using a Docker ruby:2.7.5 (when I created th project credential, but I think it doesn't matter), and currently using ruby:3.2.2.

Suddenly, when I try to edit the credentials (from host or from the container), the command go direct to outcome "File encrypted and saved.", without open the file (and decrypt).

running: rails credentials:show, I can see the file contents with no problem.

I've already given all rights to the files, delete and recreate the credentials file (together with the master.key file).

I have no clue what I should try to edit this file. Any idea? thoughts?

Upvotes: 0

Views: 1170

Answers (2)

kevinluo201
kevinluo201

Reputation: 1663

I ran into this problem today. I googled a lot and I found the best solution might be start a one-time container and install an editor in the container. For example, we can install vim and call rails credentials:edit.

docker run --rm -e EDITOR=vim [image name] /bin/bash -c "apt-get update && apt-get install -y vim && bin/rails credentials:edit"

docker-compose run --rm -e EDITOR=vim [service name] /bin/bash -c "apt-get update && apt-get install -y vim && bin/rails credentials:edit"

(Be aware that I already change the working directory in Dockerfile with WORKDIR [app root directory] so I can call bin/rails directly.)

Upvotes: 1

Joe Thor
Joe Thor

Reputation: 1260

First, verify if the docker image has an editor program. Attach to the docker container and type in your preferred text editor (vi, vim, nano, emac).

If there is no editor installed, you may need to add it to the container via the package manager.

Once you verify or install your preferred editor program, run the following command (assumes you are using vi, but swap in your editor of choice).

EDITOR='vi' rails credentials:edit

Upvotes: 0

Related Questions