Scripts with dialog from Docker container

I have a docker container which intentionally should serve node.js environment. Something similar to configuration described in this article. But I want to create my own project. Is there are a way to run npm init and generate package.json with container? If I run this command it fails on first question. How can I answer on those questions?
N.B.: Its not a problem to create this file manually(or use -y option) but I think this usercase illustrate more general concept

Note: actually it's a kind of problem to run this command with -y option. When you do that you have the same dialog with questions

A couple options

  1. You could script the answers to the questions using bash or expect.
  2. You could generate the file by answering the questions manually first, and use a docker ADD command to copy it into your container.

I'd probably choose 2. So this is more of a question about handling bash input, rather than about docker per se.