OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Attempting to install GPG in Docker Container

  • Thread starter Thread starter Jean Paul Azzopardi
  • Start date Start date
J

Jean Paul Azzopardi

Guest
I have a python workflow where I need to encrypt a file using GPG encryption keys - this will run in ECS using a Docker image.

Since GnuPG works on the basis of a “home directory”, I need to be able to install the gnupg executable in the container and have my script point to it, as such:

Code:
gpg = gnupg.GPG(gnupghome='/path/to/home/directory')

This is where I'm stuck.

My docker image is defined as such:

Code:
RUN apt-get update && apt-get install -y gnupg
RUN mkdir -p /opt/prefect/.gnupg && chmod 700 /opt/prefect/.gnupg
RUN python -m pip install --upgrade pip

COPY requirements.txt requirements.txt

RUN pip install -r requirements.txt

Where I create a directory to store the gnupg executable - so to create an instance of GPG I would do something like...

Code:
gpg = gnupg.GPG(gnupghome='/opt/prefect/')

but this returns this error:

Code:
Unable to run gpg (gpg) - it may not be available.
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/gnupg.py", line 1094, in __init__
    p = self._open_subprocess(['--list-config', '--with-colons'])
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/gnupg.py", line 1164, in _open_subprocess
    result = Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=si, env=self.env)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/lib/python3.11/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'gpg'

I then tried running which gpg in my container and it revealed this path...

Code:
/usr/bin/gpg

So I tried this...

Code:
gpg = gnupg.GPG(gnupghome='/usr/bin/')

and got the same error.

At this point I'm not sure how to proceed - any help appreciated, thanks!
<p>I have a python workflow where I need to encrypt a file using GPG encryption keys - this will run in ECS using a Docker image.</p>
<p>Since GnuPG works on the basis of a “home directory”, I need to be able to install the gnupg executable in the container and have my script point to it, as such:</p>
<pre><code>gpg = gnupg.GPG(gnupghome='/path/to/home/directory')
</code></pre>
<p>This is where I'm stuck.</p>
<p>My docker image is defined as such:</p>
<pre><code>RUN apt-get update && apt-get install -y gnupg
RUN mkdir -p /opt/prefect/.gnupg && chmod 700 /opt/prefect/.gnupg
RUN python -m pip install --upgrade pip

COPY requirements.txt requirements.txt

RUN pip install -r requirements.txt

</code></pre>
<p>Where I create a directory to store the gnupg executable - so to create an instance of GPG I would do something like...</p>
<pre><code>gpg = gnupg.GPG(gnupghome='/opt/prefect/')
</code></pre>
<p>but this returns this error:</p>
<pre><code>
Unable to run gpg (gpg) - it may not be available.
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/gnupg.py", line 1094, in __init__
p = self._open_subprocess(['--list-config', '--with-colons'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/gnupg.py", line 1164, in _open_subprocess
result = Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=si, env=self.env)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/subprocess.py", line 1026, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.11/subprocess.py", line 1955, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'gpg'

</code></pre>
<p>I then tried running <code>which gpg</code> in my container and it revealed this path...</p>
<pre><code>/usr/bin/gpg
</code></pre>
<p>So I tried this...</p>
<pre><code>gpg = gnupg.GPG(gnupghome='/usr/bin/')
</code></pre>
<p>and got the same error.</p>
<p>At this point I'm not sure how to proceed - any help appreciated, thanks!</p>
 
Top