Home > database >  Cant cd to cloned repo via Dockerfile
Cant cd to cloned repo via Dockerfile

Time:03-31

I'm creating a Dockerfile, but seem to be having some issues navigating to the folder of a cloned repo

My file contains the below

FROM ubuntu:latest
MAINTAINER cagnulein

ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/Moscow
ENV MAKEFLAGS -j8
WORKDIR /usr/local/src

RUN apt-get update && apt-get install -y tzdata
RUN apt -y update
RUN apt -y upgrade
RUN apt update -y && apt-get install -y git qt5-default libqt5bluetooth5 libqt5widgets5 libqt5positioning5 libqt5xml5 qtconnectivity5-dev qtpositioning5-dev libqt5charts5-dev libqt5charts5 qt5-default libqt5networkauth5-dev libqt5websockets5* libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev build-essential
RUN cd ~
RUN git clone https://github.com/cagnulein/qdomyos-zwift.git
RUN ls -alh
RUN cd ~/qdomyos-zwift

I successfully clone the repo, and can confirm the folder exists, but I can't seem to navigate to it as I get the following

#13 [ 9/15] RUN ls -alh
#13 sha256:4b5dfb1969e228b79ed0f0d06393eddbc97c0197582b068ad75b1e5672597867
#13 0.361 total 16K
#13 0.361 drwxr-xr-x  1 root root 4.0K Mar 30 20:31 .
#13 0.361 drwxr-xr-x  1 root root 4.0K Mar 16 20:07 ..
#13 0.361 drwxr-xr-x 17 root root 4.0K Mar 30 20:31 qdomyos-zwift
#13 DONE 0.4s

#14 [10/15] RUN cd ~/qdomyos-zwift
#14 sha256:c875dc5e19a73f6e654af2feb63f14be8a945e8eefe4882f4cd64962dd90d399
#14 0.437 /bin/sh: 1: cd: can't cd to /root/qdomyos-zwift
#14 ERROR: executor failed running [/bin/sh -c cd ~/qdomyos-zwift]: exit code: 2

Any ideas?


Tried

FROM ubuntu:latest
MAINTAINER cagnulein

ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/Moscow
ENV MAKEFLAGS -j8
WORKDIR /usr/local/src

RUN apt-get update && apt-get install -y tzdata
RUN apt -y update
RUN apt -y upgrade
RUN apt update -y && apt-get install -y git qt5-default libqt5bluetooth5 libqt5widgets5 libqt5positioning5 libqt5xml5 qtconnectivity5-dev qtpositioning5-dev libqt5charts5-dev libqt5charts5 qt5-default libqt5networkauth5-dev libqt5websockets5* libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev build-essential

RUN git clone https://github.com/cagnulein/qdomyos-zwift.git
WORKDIR /usr/local/src/domyos-zwift

RUN git submodule update --init src/domyos-zwift/src/smtpclient/
RUN git submodule update --init src/domyos-zwift/src/qmdnsengine/
WORKDIR /usr/local/src/domyos-zwift/src
RUN qmake
RUN make-j4   

which fails with

#13 [ 9/13] RUN git submodule update --init src/domyos-zwift/src/smtpclient/
#13 sha256:5c79fd971e0f758d58a0fd8a96b3c82d948311d6a3426644c3dcb9916ab9108d
#13 0.390 fatal: not a git repository (or any of the parent directories): .git
#13 ERROR: executor failed running [/bin/sh -c git submodule update --init src/domyos-zwift/src/smtpclient/]: exit code: 128
------
 > [ 9/13] RUN git submodule update --init src/domyos-zwift/src/smtpclient/:
------
executor failed running [/bin/sh -c git submodule update --init src/domyos-zwift/src/smtpclient/]: exit code: 128

CodePudding user response:

Notice in your example that you already have seen the mechanism to set the current directory: WORKDIR.

Replace all of your RUN cd ... statements with WORKDIR /path instead. That's the correct way to set the current directory in a Dockerfile.

If you need to be in another place at the end of your build, remember to add a WORKDIR toward the end of the file to leave that as the working directory in the final image.

CodePudding user response:

Your cd manipulations seem confused and completely unnecessary. Probably try something along the lines of

WORKDIR /usr/local/src

RUN apt-get update && apt-get install -y tzdata
# RUN apt -y update  # no need, you just did
RUN apt -y upgrade
# RUN apt update -y &&  # no need, you just did
RUN apt-get install -y git qt5-default libqt5bluetooth5 \
     libqt5widgets5 libqt5positioning5 libqt5xml5 \
     qtconnectivity5-dev qtpositioning5-dev libqt5charts5-dev \
     libqt5charts5 qt5-default libqt5networkauth5-dev \
     libqt5websockets5* libxcb-randr0-dev libxcb-xtest0-dev \
     libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev \
     build-essential
RUN git clone https://github.com/cagnulein/qdomyos-zwift.git
WORKDIR /usr/local/src/qdomyos-zwift

... assuming you would like to continue to run some commands in the directory you just cloned.

CodePudding user response:

~ is a shorthand for $HOME, the user's home directory. In this case this is /root. But as your ls command shows, the repo's directory is in the current directory. If you do pwd, you will see the current directory is not /root. Instead do cd qdomyos-zwift so that it is relative to the current directory.

  • Related