Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COPY command unable to find files/dir on host machine #1478

Open
masonedmison opened this issue Dec 17, 2021 · 3 comments
Open

COPY command unable to find files/dir on host machine #1478

masonedmison opened this issue Dec 17, 2021 · 3 comments
Labels

Comments

@masonedmison
Copy link

masonedmison commented Dec 17, 2021

Expected behaviour

I want to copy a directory from the host machine to the container using a command like

    dockerCommands := dockerCommands.value.flatMap {
      case Cmd("FROM", args @ _*) if args.contains("stage0") && args.contains("openjdk:11-jre-slim-buster") =>
        Seq(
          Cmd("FROM", args: _*),
          Cmd("COPY", "C:/Users/edmisml/scalaprojects/cici/certs/toKeyStore", "/certs")
        )

within my sbt.

Actual behaviour

when I docker:publishLocal it errors out at

[error]  > [stage0 2/8] COPY C:/Users/edmisml/scalaprojects/cici/certs/toKeyStore /certs:
[error] ------
[error] failed to compute cache key: "/C:/Users/edmisml/scalaprojects/cici/certs/toKeyStore" not found: not found

I thought that by inserting the COPY command after the initial FROM command (stage0) that I would indeed be able to copy files from the host machine but this does not appear to be the case.

Can someone help me out here?

Here's the out of show dockerCommands:

[info] * Cmd(FROM,WrappedArray(openjdk:11-jre-slim-buster, as, stage0))
[info] * Cmd(COPY,WrappedArray(C:/Users/edmisml/scalaprojects/cici/certs/toKeyStore, /certs))
[info] * Cmd(LABEL,WrappedArray(snp-multi-stage="intermediate"))
[info] * Cmd(LABEL,WrappedArray(snp-multi-stage-id="4961b11a-cbaa-4619-9759-2ef8e086bd75"))
[info] * Cmd(WORKDIR,WrappedArray(/opt/docker))
[info] * Cmd(COPY,WrappedArray(2/opt /2/opt))
[info] * Cmd(COPY,WrappedArray(4/opt /4/opt))
[info] * Cmd(USER,WrappedArray(root))
[info] * ExecCmd(RUN,List(chmod, -R, u=rX,g=rX, /2/opt/docker))
[info] * ExecCmd(RUN,List(chmod, -R, u=rX,g=rX, /4/opt/docker))
[info] * ExecCmd(RUN,List(chmod, u+x,g+x, /4/opt/docker/bin/cici-core))
[info] * DockerStageBreak
[info] * Cmd(FROM,WrappedArray(openjdk:11-jre-slim-buster, as, mainstage))
[info] * Cmd(USER,WrappedArray(root))
[info] * Cmd(RUN,List(id, -u, demiourgos728, 1>/dev/null, 2>&1, ||, ((, getent, group, 0, 1>/dev/null, 2>&1, ||, (, type, groupadd, 1>/dev/null, 2>&1, &&, groupadd, -g, 0, root, ||, addgroup, -g, 0, -S, root, )), &&, (, type, useradd, 1>/dev/null, 2>&1, &&, useradd, --system, --create-home, --uid, 1001, --gid, 0, demiourgos728, ||, adduser, -S, -u, 1001, -G, root, demiourgos728, ))))
[info] * Cmd(WORKDIR,WrappedArray(/opt/docker))
[info] * Cmd(COPY,WrappedArray(--from=stage0 --chown=demiourgos728:root /2/opt/docker /opt/docker))
[info] * Cmd(COPY,WrappedArray(--from=stage0 --chown=demiourgos728:root /4/opt/docker /opt/docker))
[info] * Cmd(EXPOSE,WrappedArray(8080))
[info] * ExecCmd(RUN,List(mkdir, -p, ./certs/toKeyStore))
[info] * ExecCmd(RUN,List(chown, -R, demiourgos728:root, ./certs/toKeyStore))
[info] * ExecCmd(VOLUME,List(./certs/toKeyStore))
[info] * ExecCmd(CMD,WrappedArray(mkdir, /certs/))
[info] * Cmd(COPY,WrappedArray(--from=stage0, /certs/, /certs/))
[info] * ExecCmd(RUN,WrappedArray(echo, $JAVA_HOME))
[info] * Cmd(USER,WrappedArray(root))
[info] * ExecCmd(RUN,WrappedArray(pwd))
[info] * ExecCmd(RUN,WrappedArray(ls, /))
[info] * ExecCmd(RUN,WrappedArray(ls, /certs))
[info] * ExecCmd(RUN,WrappedArray(keytool, -importcert, -alias, globalRoot, -trustcacerts, -keystore, $JAVA_HOME/jre/lib/security/cacerts, -storepass, changeit, -noprompt, -file, 
/opt/docker/certs/two.cer))
[info] * ExecCmd(RUN,WrappedArray(keytool, -importcert, -alias, globalRoot, -trustcacerts, -keystore, $JAVA_HOME/jre/lib/security/cacerts, -storepass, changeit, -noprompt, -file, 
/opt/docker/certs/one.cer))
[info] * Cmd(USER,WrappedArray(1001:0))
[info] * ExecCmd(ENTRYPOINT,List(/opt/docker/bin/cici-core))
[info] * ExecCmd(CMD,List())

Information

  • What sbt-native-packager are you using 1.9.7
  • What sbt version 1.5.5
  • What is your build system (e.g. Ubuntu, MacOS, Windows, Debian ) Windows
  • What package are you building (e.g. docker, rpm, ...) docker
  • What version has your build tool (find out with e.g. rpm --version)
  • What is your target system (e.g. Ubuntu 16.04, CentOS 7) Ubuntu
@dwickern
Copy link
Collaborator

Docker can only access files in its build context. So you will have to copy any additional files to Docker / stagingDirectory, otherwise Docker won't see them.

@masonedmison
Copy link
Author

Is there a programmatic way to do this? It looks like by default the "stage" directory is <module>/target/docker/stage.

As another approach, I tried to add a mapping tupe using Docker / fileMappings but that did not seem to have any effect on the Dockerfile nor did it add anything to the staging directory.

@dwickern
Copy link
Collaborator

Try this:

Docker / dockerPackageMappings += file("/path/to/file.txt") -> "out.txt"

@muuki88 muuki88 added the docker label Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants