I have a folder which contains all the necessary components for an app, which I want to make a container of. I have everything set up so far, with the directory /home/user/Documents/App in the Dockerfile under the ADD heading. Then when Idocker build . in the App directory I get this
ADD /home/user/Documents/App
ADD requires at least one argument
I realize that this is probably a simple fix but I am new to this so any help would be greatly appreciated. Thank you
FROM alpine
ADD </home/user/Documents/App> </home/user/Documents/DockerApp>
WORKDIR /code
RUN pip install -r requirements.txt
EXPPOSE 8080
CMD ["python", "app.py"]
You need a source and destination for the ADD command. The source here is the app folder path. The destination should be where you want the dockerfile is run.
Try this I think it might work
ADD defined in Dockerfile has the following structure
ADD sourceJarName destinationJarName
e.g.
ADD target/spring-boot-rest-docker-example-0.0.1-SNAPSHOT.jar app.jar
change your ADD likewise and try it will work
Related
I dont really understand what is WORKDIR
I have seen many sources by no one says exactyly where is that WORKDIR
I am using Windows
WORKDIR /usr/src/my_app_directory
Here is the sample from one website, it says that my workdir is /usr/src/my_app_directory.
Can I write anything as my workdir if yes where is that workdir?
Put simply it used to change the default working directly of the container e.g. The directory you are logged into when you first connect or start the container.
I am trying to perform a docker run however I keep getting the issue in the terminal which states Error: Could not find or load main class Main.
My Dockerfile is correctly named and the build did run and I can see the image when running docker run
The docker file is below:
FROM openjdk:8
COPY . /src/
WORKDIR /src/
RUN ["javac", "Main.java"]
ENTRYPOINT ["java", "Main"]
Can someone please advise me what is the best approach to take at this point or what I should be looking out for?
Thanks
It sounds like your main class name is not "Main".
after compiling with "javac" java creates a class file named exactly as its main class name. I mean the class that contains the main method.
I have a problem with 5th line of my Dockerfile. I couldn't figure out what that means.
FROM python:3.7-alpine
LABEL author= APPLE
LABEL company= PINEAPPLE
ARG HOME_DIR='/schooldata'
ADD . $HOME_DIRECT ##[ this line ]
EXPOSE 5000
WORKDIR $HOME_DIRECT
RUN pip install -r requirements.txt
ENTRYPOINT ["python", "app.py"]
Here :
ADD . $HOME_DIRECT
ADD performs a resource copy from a source to the current built image with the following specificity : if that is recognized as an archive (tar,zip...), it copies its content, otherwise it copies the contained files/directories such as.
The two next arguments are the source resource and the target resource of ADD.
. means that the source is the build context. Build context is the last argument of the docker build command : often we specify . such as docker build FooTag . to represent the current directory where the docker build command is executed but that may be different.
$HOME_DIRECT is the target directory of the copy inside the built image.
As a side note, ADD has a quite complex behavior (it also may accept URL as source, so it should be favored over COPY only for special cases (URL and copy archive's content).
In most of cases that is indeed better :
COPY . $HOME_DIRECT
It will add the content of your working directory (where the build command has been executed) into you image in the location defined in environment variable HOME_DIRECT
More details: here
I am trying to create a dockerfile that adds files from build directory to the working directory.
The build directory can vary and thus needs to be specified by an argument:
ARG BUILD_SOURCE
FROM node:8.11.4
WORKDIR /usr/local/app
ADD "$BUILD_SOURCE" .
I ran this with docker build BUILD_SOURCE=bin/bundle ..
Somehow the ARG is not substituted so that the whole current directory is added to the image.
When I hardcode the build source it works fine.
I have tried using ENV instead, copying the arg into the the env like this:
ENV BUILD_SOURCE $BUILD_SOURCE
ADD "${BUILD_SOURCE}" .
That didn't work either.
In the official docker documentation I cannot find this behaviour being mentioned.
Does anybody why this is happening and what possible workaround would be?
Ok, I figured it out.
The ARG must be placed below the FROM statement unless it is used within the FROM statement:
FROM node:8.11.4
ARG BUILD_SOURCE
WORKDIR /usr/local/app
ADD "$BUILD_SOURCE" .
FROM "this line works but cant show code"
RUN yum install -y java-1.8.0-openjdk.x86_64 && yum clean all
COPY /resources/accounts.txt /home/resources/accounts.txt
COPY elk_casino_server /home/elk_casino_server
CMD ["jar","cvmf","/home/elk_casino_server/src/META-INF/MANIFEST.MF","/home/server.jar","/home/elk_casino_server/src/Main.class"]
CMD ["java","-jar","/home/server.jar"]
Please take a little more time to format your code snippets correctly and to make sure you ask a clear question.
Your Dockerfile uses the COPY instruction to copy two resources into your container image:
/resources/accounts.txt (available within the image at /home/resources/accounts.txt)
/elk_casino_server (available within the image at /home/elk_casino_server)
Unfortunately, your CMD instructions are trying to execute something very different. Only one command instruction can be defined and the latter will be accepted, which is:
CMD ["java","-jar","/home/server.jar"]
At no point do you copy /home/server.jar into your container image.
The parameter order of the char command seems to be wrong. The manifest-addition should come after the jar-file, not before it.
jar cfm jar-file manifest-addition input-file(s)
see: Packaging Programs in JAR Files: Modifying a Manifest File
Also: If there are more than one CMD, the last one overrides the others. Since I think you want to pack the jar at build time, RUN might be a better choice.
Both points combined:
RUN jar cvmf /home/server.jar /home/elk_casino_server/src/META-INF/MANIFEST.MF /home/elk_casino_server/src/Main.class