2

I am new to Docker and having a go at getting my Angular web app to build and run in a container.

I have a very basic Dockerfile at the root of the project like so:

# Create the image based on the official Node 10.13.0 image from Dockerhub
FROM node:10.13.0 as node

# Copy dependency definitions
COPY package.json .

# Install dependencies using npm
RUN npm install

# TODO - copy rest of app and run angular-cli build commands to serve up the app

And upon running a build command against it I am hitting the following error:

enter image description here

I realise from looking up this error, that I haven't yet supplied any host key details from my host machine so these can be used for accessing private repo's.

I came across some old answers here on approaches to supplying my host key details such as this one, but I didn't get much further, still getting the same error.

I was able to confirm I was referencing my host key correctly by echoing these out in my dockerfile and seeing the details in my terminal.

Anyway, I am unsure what the correct or official way is of doing this.

I am running Docker 2.0.0.0-maxc78 and on macOS High sierra

Can anyone please point me in the right direction as to what the correct approach is here please?

Thanks!

phd
  • 82,685
  • 13
  • 120
  • 165
mindparse
  • 6,115
  • 27
  • 90
  • 191

1 Answers1

2

This kind of scenario would benefit from the recent docker build secret.

docker build --secret id=mysite.key,src=path/to/mysite.key .

That is used in your Dockerfile as:

# syntax=docker/dockerfile:1.0.0-experimental

FROM alpine

RUN --mount=type=secret,id=mysite.key command-to-run

See more with "Build secrets and SSH forwarding in Docker 18.09" (your docker 2.0.0 should support it)

In your case, your Dockerfile should include:

RUN --mount=type=ssh git clone git@github.com:myorg/myproject.git myproject

On the docker client side, you need to define that SSH forwarding is allowed for this build by using the --ssh flag.

docker build --ssh default .

The flag accepts a key-value pair defining the location for the local SSH agent socket or the private keys.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250