Docker file:
# copy over system jboss configs
ARG SYSTEM_TYPE
COPY $SYSTEM_TYPE/AP/standalone.conf $JBOSS_HOME/bin/standalone.conf
COPY $SYSTEM_TYPE/AP/standalone-ha-bob.xml $JBOSS_HOME/bin/standalone-ha-bob.xml
Docker Command:
docker build --build-arg SERVER_TYPE=jbossconf/ENT-UAT/ -f /usr/etc/repos/docker-files/test-dockerfile-app -t appserver/test:1.0 .
Docker Build Result:
Step 15 : COPY $SYSTEM_TYPE/AP/standalone.conf $JBOSS_HOME/bin/standalone.conf
lstat AP/standalone.conf: no such file or directory
The --build-arg does not appear to be passing to the dockerfile. Where am I going wrong?
On your build args you are passing SERVER_TYPE and referencing $SYSTEM_TYPE on your dockerfile, that should fix it!
Related
I have multiple projects/folders inside a single directory called root. There is a common Dockerfile that runs all projects/folders. I run the projects passing different build context in docker build command as below:
$ docker build -t project1:1.0.0 -f . root/project1
$ docker build -t project2:1.0.0 -f . root/project2
$ docker build -t project2:1.0.0 -f . root/project3
Now, I need to add some conditions based on docker build context in dockerfile. Can that be done? I didn't find a way to get docker build context.
I think you can pass the project name to the Dockerfile as an argument and build for instance:
ARG ENV
RUN if [ "$ENV" = "production" ] ; then yarn client:build:prod ; else yarn client:build ; fi
finally:
docker build -t node-image . --build-arg ENV=production
How to read current docker tag inside dockerfile?
Example:
// run in cmd
docker build . -t thisismytag
// docker file
FROM node:14-alpine AS build
RUN echo $TAG // prints thisismytag
You could pass in the tag as a separate argument
docker build -t thisismytag --build-arg TAG=thisismytag
and in the dockerfile
FROM node:14-alpine AS build
ARG TAG=unknown
RUN echo $TAG // prints thisismytag
But, as already stated in a comment, the image tag may change after the image was built. This would not be reflected in the image.
Dockerfile is:
FROM nginx
COPY html /usr/share/nginx/html
Dockerfile is in pwd directory(which is home/ubuntu/app), when use following command:
docker build -t mynginx .
I was giving an error:
copy failed: stat /var/lib/docker/tmp/docker-builder344/html: no such file or directory.
how to change docker source of the context of the build?
Docker build only look files in Dockerfile file context, mean the build will copy /home/ubuntu/app/ from this location where your Dockerfile is.
So better to place your html the /home/ubuntu/app in this location as docker build send tar of the context to docker daemon so it is recommended to keep the context minimal.
docker build -t mynginx . would expect to find Dockerfile in the current directory. Moreover, relative paths used by Dockerfile instructions would be relative to the current directory.
You can set the build context path to a different path docker build -t mynginx [some_folder_path]. Docker would search for Dockerfile there. You can modify the path to Dockerfile using -f option docker build -f [path_to_dockerfile] -t mynginx [some_folder_path]
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.