I’m running docker [Docker 18.06.1-ce, build e68fc7a] on an Ubuntu 18 machine.
Simply carrying out a very simple exercise from docker in order to build a dockerfile : https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
On running the following command
docker build -t helloapp .
I get the following error
error checking context: 'can't stat '/home/aielloine/.docker/helloapp/dockerfiles''.
The docker file:
FROM busybox
COPY /hello
RUN cat /hello
You are missing the source, i.e. the file you want to copy inside the iamge, in your COPY command:
FROM busybox
COPY <source> /hello
# ^
# |
# This is missing
RUN cat /hello
Related
Here my DockerFile :-
FROM openjdk:10
ENV AQUILA_HOME /data/config
#USER root
#VOLUME /tmp
ADD a2i-web-1.0.0-SNAPSHOT.jar app.jar
#RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-jar","app.jar"]
My jar is spring boot application which refers configuration file from some directory [/data/config/config.properties]
I am building DockerFile successfully by command
sudo docker build -t dockImgName/a2i-web:v1 .
But while running it by command
sudo docker run -p 8080:8080 -t dockImgName/a2i-web:v1
giving exception as :
Caused by: java.io.FileNotFoundException: /data/config/config.properties (No such file or directory)
I am running this dcoker command from directory containing DockerFile and my jar
Do I need to set any configuration to get config file directory?
The error message is quite clear. When the container tries to run it is not able to find properties file.
You need to add config.properties file to your docker image.
ADD path_to_config_file/config.properties /data/config/config.properties
NOTE: path_to_config_file refers to the file path in your local where you are building the dockerfile
I was following the tutorial on the official website.
https://docs.docker.com/get-started/part2/#build-the-app
I created a directory named dir and added the Dockerfile, app.py and requirements.txt. When I try to build this, the error is-
root#ubuntu:~/dir# docker build -t hello
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | - [flags]
Build an image from a Dockerfile
You forgot to mention location of context-root
#>docker build -t hello .
Add a . at the end if Dockerfile is at the current location
I have below Dockerfile:
FROM python:3
RUN mkdir -p /test/code/
RUN mkdir -p /test/logs/
RUN mkdir -p /test/configs/
ADD test.py /test/code/
ADD test_output.txt /test/code/
ADD test_input.txt /test/configs/
ADD logfile.log /test/logs/
CMD [ "python3", "/test/code/test.py" ]
My directory structure is:
/home/<username>/test/
|-> code/Dockerfile, test_output.txt, test.py
|-> logs/logfile.log
|-> configs/test_input.txt
when I am building the docker image using below command:
sudo docker build -t myimage .
It shows below error:
Step 7/9 : ADD test_input.txt /test/configs/
ADD failed: stat /var/lib/docker/tmp/docker-builder562406652/test_input.txt: no such file or directory
Why it shows this error when I have the directory and my file is also present.
This doesn't work because test_input.txt is not in the docker build context.
When you execute the command sudo docker build -t myimage . the last '.' indicates the build context. What docker does is that it uploads the context to the docker deamon to build the image. In your case the context does not contain test_input.txt, thus it is not uploaded and docker can't find the file/
There are two ways to solve this:
Inside test directory run the command sudo docker build -t myimage -f code/Dockerfile .. In this case the context includes all the test directory. Then modify the Dockerfile to account for this change:
FROM python:3
...
ADD code/test.py /test/code/
ADD code/test_output.txt /test/code/
ADD config/test_input.txt /test/configs/
ADD logs/logfile.log /test/logs/
The second option is to simply move the Dockerfile to the test folder and modify it as above. In that case the command sudo docker build -t myimage . should work.
Also make sure to not add in the .dockerignore file a file or folder that is needed during the image building process.
Because test_input.txt is in another directory,either put this file in place where dockerfile is there similar to test_output.txt or give full path in ADD command
ADD ../configs/test_input.txt /test/configs/
Even for logfile.log this u will get error , so change to
ADD ../logs/logfile.log /test/logs/
I have made images ubuntu 14:04 on dockerfile
I am running the syntax
$ sudo docker build -t mypostgres .
but I am still confused as to build the dockerfile
how to build it?
sudo docker build -t mypostgres . means:
process the file named 'Dockerfile' (default name)
located in the current folder (that is the final .)
and build as a result the image named mypostgres
So if you have a Dockerfile starting with FROM postgres, you can execute your command and have your own postgres image in no time.
Dockerfile is not as complex as it looks. here's a good start article that could help you to build your first docker file easily - http://rominirani.com/2015/08/02/docker-tutorial-series-writing-a-dockerfile/
You may want to read the doc of Dockerfile best practice by Docker, better than any article IMHO.
You can build a docker file direct from git repository or from a director.
to build a docker file first create a docker file inside your project and name it just Docker without any extension. Now inside that file write necessary command for building an image. For example
FROM node:alpine
WORKDIR /app
COPY package.json ./
RUN npm install
COPY ./ ./
CMD ["npm", "start"]
->Build from git:
sudo docker build https://github.com/lordash/mswpw.git#fecomments:comments
in here:
fecomments is branch name and comments is the folder name.
->building from git with tag and version:
sudo docker build https://github.com/lordash/mswpw.git#fecomments:comments -t lordash/comments:v1.0
->Now if you want to build from a directory: first go to comments directory the run command sudo docker build .
->if you want to add tag you can use -t or -tag flag to do that:
sudo docker build -t lordash . or sudo docker build -t lordash/comments .
-> Now you can version your image with the help of tag:
sudo docker build -t lordash/comments:v1.0 .
->you can also apply multiple tag to an image:
sudo docker build -t lordash/comments:latest -t lordash/comments:v1.0 .
I can't seem to get docker build to run correctly:
wangyaos-MBP-3:~ wangyao$ cd /Users/wangyao/Ozintel/docker/flexcloud/
wangyaos-MBP-3:flexcloud wangyao$ ls
Dockerfile apache-tomcat-7.0.62 jdk1.8.0_45.jdk
wangyaos--3:flexcloud wangyao$ docker build -t="Users/wangyao/Ozintel/docker/flexcloud" .
Invalid namespace name (Users). Only [a-z0-9-_] are allowed.
wangyaos-MBP-3:flexcloud wangyao$ cd /Users/wangyao/
wangyaos-MBP-3:~ wangyao$ docker build -t="Users/wangyao/Ozintel/docker/flexcloud" .
Cannot locate Dockerfile: Dockerfile
wangyaos-MBP-3:~ wangyao$ docker build -t="Users/wangyao/Ozintel/docker/flexcloud"
docker: "build" requires 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build a new image from the source code at PATH
How should I use docker build?
Slow down and take a look at the docs.
To use docker build, the easiest way is to cd into the directory with the Dockerfile then run something like:
$ docker build -t flexcloud .
The -t argument specifies the repository name and tag, not the directory with the Dockerfile. If you want to give a path to a different Dockerfile, you can use the -f argument. The . at the end specifies the "build context", in this case the current working directory.