I am having issues setting up a Dockerfile in Ubuntu. I tried the following command:
sudo docker build -t chaste .
But when it reaches to the following command:
RUN chmod +x chaste.sh && ./chaste.sh -q && rm -f chaste.sh
I get the following error:
chmod: cannot access 'chaste.sh': No such file or directory
However, chaste.sh is in the current directory. I am not sure why it complains about not being able to find it.
I would appreciate it if someone could help me out.
To use the file from current directory you should add it from build context to the container by adding the following command above RUN command in your Dockerfile:
ADD ./chaste.sh ./chaste.sh
Related
EDIT to provide MRE:
Steps to reproduce (using Docker CLI, now, for reproducibility)
project_directory
Dockerfile
directory_to_cd_into
gradlew
Dockerfile:
From debian:9
RUN cd /directory_to_cd_into
# also tried RUN cd ./directory_to_cd_into
Running docker build yields /bin/sh: 1: cd: can't cd to /directory_to_cd_into
So the problem is cd -- which means I must be missing something really basic about container directory structure.
Also tried WORKDIR
Happy to add more info.
Original:
From within my container, I can successfully build using gralde as follows:
cd directory/with/gradlew && chmod +x gradlew && ./gradlew build
But when I put this in my Dockerfile and try to build the container, it fails with "file or directory gradlew does not exist":
RUN cd directory/with/gradlew && chmod +x gradlew && ./gradlew build.
From this question, Unable to change directories while building docker Image using Dockerfile , I am aware that cd resets with every RUN statement -- but I'm doing this all from within a single RUN.
Everything prior to this RUN statement is held constant, i.e., if I comment out the RUN, and build interactively from the command line in the image, it builds fine.
If it matters, I'm doing all this from within a GitHub codespace; I'm not using the Docker CLI directly.
What am I doing wrong?
--
EDIT: I must be trying to include/cd directories from outside the build context. I'm not sure how to fix that yet -- maybe with COPY?
I just started playing around with Docker yesterday and am having issues between the build environment and the run environment. Build wise I have issues like...
RUN install.sh
/bin/sh: 1: install.sh: Permission denied
the command '/bin/sh -c install.sh' returned a non-zero code: 126
or ...
RUN . sourceme.env
/bin/sh: 1: .: sourceme.env: not found
The command '/bin/sh -c . sourceme.env' returned a non-zero code: 2
I build using 'sudo docker build -t joes' and
I run using 'sudo docker run -it joes'
The frustrating thing is that after build failure I can run it, see that I am in the working directory I expected, and run the command that failed during building successfully. So why the discrepancy?
This is on a linux system and I'm using 'FROM ubuntu:18.04'
To bypass the RUN install.sh error I used
RUN /bin/sh install.sh
which converts to
/bin/sh -c /bin/sh install.sh
Post your entire Dockerfile. The problem is you haven't pointed to the correct location. When you copy it, copy it in and then supply it with the absolute path.
e.g.
COPY install.sh /install.sh
CMD ./install.sh
EDIT: if your containers main job is to run the install.sh script then use it with CMD and not RUN. Use run to build env and evth else.
Using the RUN instruction in a Dockerfile with 'source' does not work Seems to be the bulk of my issue
That along with running multiple RUN commands instead of RUN ... && ... && ... etc
Trying to figure out how to use this command is frustrating. Apparently the files have to be inside the build context but now I've moved the file into the build context (or at least I think I have) and I'm still getting the same error:
INFO[0000] No source files were specified
Here's the directory structure on the host:
/srv/uwsgi/
- Dockerfile
- uwsgi.ini
Here's the pertaining commands of my dockerfile:
FROM ubuntu:trusty
RUN sudo mkdir -p /srv/www/cc/
ADD ["./uwsgi.ini" "/srv/www/uwsgi.ini"]
Tried several variations on the ADD, with ./ and without, having the file outside of context and the full path.. What am I missing?
To ADD files in a Dockerfile:
FROM ubuntu:trusty
RUN sudo mkdir -p /srv/www/cc/
ADD ./uwsgi.ini /srv/www/uwsgi.ini
Working with Docker and I notice almost everywhere the "RUN" command starts with an apt-get upgrade && apt-get install etc.
What if you don't have internet access and simply want to do a "dpkg -i ./deb-directory/*.deb" instead?
Well, I tried that and I keep failing. Any advice would be appreciated:
dpkg: error processing archive ./deb-directory/*.deb (--install):
cannot access archive: No such file or directory
Errors were encountered while processing: ./deb-directory/*.deb
INFO[0002] The command [/bin/sh -c dpkg -i ./deb-directory/*.deb] returned a non-zero code: 1`
To clarify, yes, the directory "deb-directory" does exist. In fact it is in the same directory as the Dockerfile where I build.
This is perhaps a bug, I'll open a ticket on their github to know.
Edit: I did it here.
Edit2:
Someone answered a better way of doing this on the github issue.
* is a shell metacharacter. You need to invoke a shell for it to be expanded.
docker run somecontainer sh -c 'dpkg -i /debdir/*.deb'
!!! Forget the following but I leave it here to keep track of my reflexion steps !!!
The problem comes from the * statement which doesn't seem to work well with the docker run dpkg command. I tried your command inside a container (using an interactive shell) and it worked well. It looks like dpkg is trying to install the so called ./deb-directory/*.deb file which doesn't exist instead of installing all the .deb files contained there.
I just implemented a workaround. Copy a .sh script in your container, chmod +x it and then use it as your command.
(FYI, prefer using COPY instead of ADD when the file isn't remotely copied. Check the best practices for writing Dockerfiles for more info.)
This is my Dockerfile for example purpose:
FROM debian:latest
MAINTAINER Vrakfall <jeremy#artphotolaurent.be>
COPY install.sh /
#debdir is a directory
COPY debdir /debdir
RUN chmod +x /install.sh
CMD ["/install.sh"]
The install.sh (copied at the root directory) simply contains:
#!/bin/bash
dpkg -i /debdir/*.deb
And the following
docker build -t debiantest .
docker run debiantest
works well and install all the packages contained in the /debdir directory.
I created a Dockerfile in my root.
FROM ubuntu:12.04
MAINTAINER Bhim Singh <bhim3003#gmail.com>
RUN apt-get y install java
CMD echo hello
then i tried to run this command : sudo docker build -t bhim3003/myjava .
I am recieving this error:
" Error checking context is accessible: 'can't stat '.gvfs''. Please
check permissions and try again."
And docker image is not created. Any suggestions?
I faced the same issue while working with boot2docker on Windows 7. However I was able to build it successfully after moving dockerfile outside home directory.
In my case this issue is occurred because when we call docker build all files searched in working directory and as docker does not run with administrator privilege cannot access to some files and this error generated.
Solution:
Move to directory which all user can accessed (for example: /c)
Create new directory (sep)
Create Dockerfile in new directory
Run build
commands:
$ cd /c
$ mkdir sep
$ cd sep
$ touch Dockerfile
# vi Dockerfile
# docker build -t fahsep/debian