Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No such file or directory in docker build

Tags:

docker

I am new to docker and attempting to port an app over to it. Essentially, on startup, the app needs to perform some environment dependent work which I have encapsulated in a script.

My app looks like

Dockerfile
scripts/run.sh
build-development/stuff
build-production/stuff

Here is my Dockerfile:

FROM nginx
RUN chmod +x scripts/run.sh
CMD ["scripts/run.sh", APP_ENV]
EXPOSE 80

and here is scripts/run.sh:

#!/bin/bash

mkdir dist

chmod -R 777 dist

if [ $1 == "development" ]
then
    cp -R build-development/. /usr/share/nginx/html
fi

if [ $1 == "stage" ]
then
    cp -R build-production/. /usr/share/nginx/html
    sed -i 's/production/stage/g' dist/index.html
fi

if [ $1 == "production" ]
then
    cp -R build-production/. /usr/share/nginx/html
fi

The idea is that I will run the image like:

docker run -e APP_ENV=development app-name

and it will be fed into the script, which will copy the correct files.

Unfortunately, I never get to run the image because during the build step:

docker build -t app-name .

I get errors about

scripts/run.sh not being a file or directory

I don't understand why I am getting this error, I guess it is from naive misunderstanding on my part. What am I doing wrong and how can I make my project work?

Thanks in advance.

like image 875
pQuestions123 Avatar asked Feb 14 '17 01:02

pQuestions123


People also ask

Does Docker Workdir create directory?

It also sets the working directory of a Docker container, which means if we have specified any path using WORKDIR and when we connect the container using the 'exec' command, then it will directory land us to that directory. Docker daemon creates the folder if the specified directory does not exist.

How do I make Docker without cache?

How to Use the Docker Build --no-cache Option. There can be different reasons for disabling the build-cache. You can rebuild the image from the base image without using cached layers by using the --no-cache option. New layers were constructed and used.

What does Workdir mean in Docker?

The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile. Any RUN , CMD , ADD , COPY , or ENTRYPOINT command will be executed in the specified working directory.


1 Answers

It seems like you want scripts/run.sh to be a part of the container. In that case, before you try to run the chmod you need to copy it into the image.

FROM nginx
COPY scripts/run.sh /scripts/run.sh
RUN chmod +x /scripts/run.sh
CMD ["/scripts/run.sh", APP_ENV]

This will copy ./scripts/run.sh (relative to your build directory) into the image at /scripts/run.sh, so your later RUN and CMD have that path available.

like image 113
Dan Lowe Avatar answered Sep 30 '22 19:09

Dan Lowe