0

I'm trying to add a private key docker-upload to a docker container:

FROM centos:7

RUN yum -y -q install openssh-clients && \
  yum clean all && \
  rm -rf /var/cache/yum

RUN \
  mkdir -p ~/.ssh && \
  touch ~/.ssh/known_hosts && \
  ssh-keyscan -p 2022 -t rsa hostname > ~/.ssh/known_hosts

COPY docker-upload ~/.ssh/

RUN ls -all ~/.ssh

When building with

docker build --no-cache -t privateregistry.com/build-containers:upload .

I get that the ~/.ssh directory is empty:

Step 5/7 : COPY docker-nerds-upload ~/.ssh/
 ---> 2bafa09dd03c
Step 6/7 : RUN ls -all ~/.ssh
 ---> Running in 1c74fc1d0e14
total 8
drwxr-xr-x 2 root root 4096 Apr 18 14:19 .
dr-xr-x--- 3 root root 4096 Apr 18 14:19 ..
-rw-r--r-- 1 root root    0 Apr 18 14:19 known_hosts

Why doesn't COPY docker-upload ~/.ssh/ copy the file docker-upload into the ~/.ssh directory in the docker container?

mles
  • 4,534
  • 10
  • 54
  • 94

2 Answers2

2

The dest is an absolute path, or a path relative to WORKDIR, into which the source will be copied inside the destination container.

Reference(Dockerfile COPY)

Tilde(~) expansion for COPY is not supported.

SangminKim
  • 8,358
  • 14
  • 69
  • 125
1

Somehow COPY doesn't like ~ as path. With absolute paths it works

COPY docker-upload /root/.ssh
mles
  • 4,534
  • 10
  • 54
  • 94