user1513388
user1513388

Reputation: 7441

Docker Exec with OpenSSL and stdin, stdout

I'm trying to use docker exec with OpenSSL and piping like this. I have a container thats running called test1.

1. openssl genrsa -des3 -passout pass:123 2048 | docker exec -i test1 sh -c 'cat >/key.pem
2. docker exec test1 cat key.pem
    -----BEGIN RSA PRIVATE KEY-----
    Proc-Type: 4,ENCRYPTED
    DEK-Info: DES-EDE3-CBC,DE60A9F33B9E508D

    /uJYBfM6YwCkIgrgQSH......
3. docker exec test1 cat key.pem | openssl req -subj '/CN=client' -new -key -out client.csr -passin pass:123

write /dev/stdout: broken pipe

If I run these commands without using docker they work OK. Is/does docker do anything different with the stdin and stdout streams ?

Upvotes: 1

Views: 1760

Answers (1)

Armin Braun
Armin Braun

Reputation: 3683

You should be able to fix this by doing two things:

  1. Make the output line buffered as suggested above, meaning the docker command becomes docker exec -t test1 cat key.pem
  2. The way you are running things right now, it is not really clear where the docker exec arguments end and where the redirection via the | starts. Simply change the overall command to something that makes this clear to bash, this should work

docker exec -t test1 cat key.pem | openssl req -subj '/CN=client' -new -key /dev/stdin -passin pass:123

Upvotes: 2

Related Questions