Search code examples
dockerubuntuarmgitlab-cidocker-in-docker

echo to file in docker file fails when building from armhf/ubuntu in dind


I am using CI pipelines on Gitlab to build docker images for deployment to Raspbian. Since my builds need to access some private NPM packages, I include in the Docker file the following line which creates a token file using the value stored in environment variable $NPM_TOKEN:

RUN echo //registry.npmjs.org/:_authToken=$NPM_TOKEN > ~/.npmrc

This works fine when building from my usual image (resin/raspberrypi3-node). However one of my containers is built from armhf/ubuntu. When the above line is executed, the build fails with the following error:

standard_init_linux.go:207: exec user process caused "no such file or directory"
The command '/bin/sh -c echo //registry.npmjs.org/:_authToken=$NPM_TOKEN >> ~/.npmrc' returned a non-zero code: 1

The build runs fine from docker build on my development machine (Windows 10) but not within the gitlab pipeline.

I have tried stripping down my docker and pipeline files to the bare minimum, and removed the environment variable and the tilde from the path, and this still fails for the ubuntu (but not the resin) image.

Dockerfile.test.ubuntu:

FROM armhf/ubuntu

RUN echo hello > world.txt

Dockerfile.test.resin:

FROM resin/raspberrypi3-node

RUN echo hello > world.txt

gitlab-ci.yml:

build_image:
  image: docker:git
  services:
  - docker:dind
  script:
  - docker build -f Dockerfile.test.resin . # Succeeds
  - docker build -f Dockerfile.test.ubuntu . # Fails
  only:
    - master

I have searched for similar issues and have seen this error reported when running a .sh file which contained CRLF combinations. Although I am developing on Windows, my IDE (VS Code) is set up to use LF, not CRLF and I have checked all the above files for compliance.


Solution

  • As in here, try and use double-quotes for your echo argument:

    RUN echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
    

    And first, in your Dockerfile, do a RUN ls -alrth ~/ to check the accessibility/presence of the target folder.

    That error was also reported in this thread (without any answer), with an example where the final version of the Dockerfile, as seen here, use this .gitlab-ci.yml.

    The OP bighairdave confirms in the comments:

    I copied the following from the example @VonC gave, and it worked:

    variables: 
      DOCKER_HOST: "tcp://docker:2375" 
      DOCKER_DRIVER: overlay2 
    before_script: 
      - docker run --rm --privileged hypriot/qemu-register