I am trying to build a docker image that will copy my cpp file from my host machine to the docker container, compile it and finally I will run it. I am facing a problem where I am unable to copy from source file cpp file from host to the docker container. I checked the docker document and it says I should use -f- option but when I do that the docker build just hangs. Here is my docker file
FROM debian:stretch-slim as base
RUN apt-get update && apt-get install -y --no-install-recommends \
sudo \
vim \
nano \
tree \
git \
locales \
locales-all \
ssh \
python3 \
less \
net-tools \
iputils-ping \
gcc \
g++ \
meson \
ninja-build
WORKDIR /root
COPY docker_test.cpp ./
COPY meson.build ./
RUN meson builddir
RUN cd builddir
RUN ninja docker_test
ENTRYPOINT ["/bin/bash", "-c"]
CMD ["./docker_test"]
I am trying to build this docker file. My docker_test.cpp lives inside my host machine and it is in the same folder
Error I get is
docker build ./Docker/
Sending build context to Docker daemon 2.048kB
Step 1/10 : FROM debian:stretch-slim as base
---> da2dadc5e951
Step 2/10 : RUN apt-get update && apt-get install -y --no-install-recommends sudo vim nano tree git locales locales-all ssh python3 less net-tools iputils-ping gcc g++ meson ninja-build
---> Using cache
---> c4985c6dd624
Step 3/10 : WORKDIR /root
---> Running in b5e340b626e3
Removing intermediate container b5e340b626e3
---> eb8ba73448a3
Step 4/10 : COPY docker_test.cpp ./
COPY failed: stat /var/lib/docker/tmp/docker-builder742117699/docker_test.cpp: no such file or directory
My folder structure -
ls -l
total 16
drwxrwxr-x 2 sh sh 4096 Apr 18 13:30 Docker
-rwxrwxr-x 1 sh sh 197 Apr 18 12:58 docker_test.cpp
-rwxrwxr-x 1 shr sh 69 Apr 18 12:58 meson.build
-rwxrwxr-x 1 sh sh 399 Apr 18 12:58 README.txt
The Dockerfile lives inside the folder Docker.
RUNdirective gets executed in its own shell context, so if youcdin oneRUNyou will automatically go back to theWORKDIRwhen that command is finished. The 'docker' way to do it would either be to change yourWORKDIRagain or to specify the full path to an executable.