I'm trying to move my few microservices to a docker containers using docker-compose project type from Visual Studio.
I also have Service Fabric project so I have to install Service Fabric SDK into my docker containers.
That's what I do to achieve this (my dockerfile(s)):
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80
...
WORKDIR /temp
ADD https://aka.ms/vs/15/release/vs_buildtools.exe /temp #C:\TEMP\vs_buildtools.exe
...
The rest code doesn't matter since it crashes on line with ADD command.
The error from Output after I run this via Ctrl+F5:
3>Step 4/11 : ADD https://aka.ms/vs/15/release/vs_buildtools.exe /temp
3>Service 'bmt.microservices.snowforecastcenter' failed to build: ADD failed: CreateFile \\?\C:\ProgramData\Docker\tmp\docker-builder567273413\temp: The system cannot find the file specified.
I don't understand what I'm doing wrong and what does it mean 'system cannot find the file' since I simply load the file from the internet and place it into my newly created \temp folder (the link is valid, I checked).
Does anybody know what this might be related to?
Ok, I've accidentally fixed the problem by moving comment to next line.
From this:
ADD https://aka.ms/vs/15/release/vs_buildtools.exe /temp #C:\TEMP\vs_buildtools.exe
To this:
ADD https://aka.ms/vs/15/release/vs_buildtools.exe /temp
#C:\TEMP\vs_buildtools.exe
Then I red on official site (https://docs.docker.com/engine/reference/builder/#/from) that you cannot have inline comments since they are treated as arguments:
Docker treats lines that begin with # as a comment, unless the line is a valid parser directive. A # marker anywhere else in a line is treated as an argument.
I hope this will help other people who are new in Docker.
Related
I am trying to follow the 2 steps mentioned below:
1) Downloaded source code of
https://sourceforge.net/projects/hunspell/files/Hyphen/2.8/hyphen-2.8.8.tar.gz/download
2) Compiled it and you will get binary named example:
hyphen-2.8.8$ ./example ~/dev/smc/hyphenation/hi_IN/hyph_hi_IN.dic
~/hi_sample.text
I have downloaded and uncompressed the tar file. My question is how to create a dockerfile to automate this?
There are only 3 commands involved:
./configure
make all-recursive
make install
I can select the official python image as a base container. But how do I write the commands in a docker file?
You can do that with a RUN command:
FROM python:<version number here>
RUN ./configure && make-recursive && make install
CMD ['<some command here>']
what you use for <some command here> depends on what the image is meant to do. Remember that docker containers only run as long as that command is executing, so if you put the configure/make/install steps in a script and use that as your entry point, it's going to build your program, and then the container will halt.
Also you need to get the downloaded files into the container. That can be done using a COPY or an ADD directive (before the RUN of course). If you have the tar.gz file saved locally, then ADD will both copy the file into the container and expand it into a directory automatically. COPY will not expand it, so if you do that, you'll need to add a tar -zxvf or similar to the RUN.
If you want to download the file directly into the container, that could be done with ADD <source URL>, but in that case it won't expand it, so you'll have to do that in the RUN. COPY doesn't allow sourcing from a URL. This post explains COPY vs ADD in more detail.
You can have the three commands in a shell script and then use the following docker commands
COPY ./<path to your script>/<script-name>.sh /
ENTRYPOINT ["/<script-name>.sh"]
CMD ["run"]
For reference, you can create your docker file as they have created for one of the projects I worked on Apache Artemis Active Mq:
https://github.com/apache/activemq-artemis/blob/master/artemis-docker/Dockerfile-ubuntu
I'm trying to create an easy-to-use Docker image for the Garry's Mod server. While my Docker image builds just fine, running it as a container always results in a single error: /bin/sh: 1: ./easygmod.sh: Permission denied.
I'm using the cm2network/steamcmd image as a base. I have tried both tags that the aforementioned base image has. I have tried chmod +x, changing users to root, and fiddling with the shebang in the first line of the easygmod.sh script, as well as a number of possible typos, particularly in file names and paths.
I have a GitHub repository for this project which auto-builds to Docker Hub. Currently, the lines of code involving the problematic script are:
# Start main script
ADD easygmod.sh .
RUN chmod +x easygmod.sh
USER steam
CMD ./easygmod.sh
Also, the shebang/first line of the script is currently #!/bin/sh.
Despite having no logical explanation, the easygmod.sh script refuses to be executed, always throwing the error Permission denied. This especially confusing given that my only other public GitHub project, which is very similar (similar style Docker image with the same base OS as cm2network/steamcmd), never had any issues like this.
The file isn't owned by steam in the container, so the chmod +x was insufficient. Either add --chown=steam to the ADD, or change your chmod from +x to a+rx.
Also, you didn't specify CWD or a path to put those files in. It's likely that the root version of that image has a CWD that steam can't access. You should use /home/steam/ for that instead.
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
Hopefully someone can help me see the wood for the trees as they say!
I am no Linux expert and therefore I am probably missing something very obvious.
I have a dockerfile which contains the following:
FROM node:9.8.0-alpine as node-webapi
EXPOSE 3000
LABEL authors="David Sheardown"
COPY ["package.json", "npm-shrinkwrap.json*", "./"]
RUN npm install --production --silent && mv node_modules ../
COPY . /home/vsts/work/1/s/
CMD ["node", "index.js"]
I then have an Azure pipeline setup as the following image shows:
My issue seems to be the build process cannot find the dockerfile itself:
##[error]Unhandled: No Dockerfile matching /home/vsts/work/1/s/**/Dockerfile was found.
Again, apologies in advance for my lack of Linux knowledge.. there is something silly I have done or not done ;)
P.S: I forgot to mention in Azure Pipelines I am using "Hosted Linux Preview"
-- UPDATE --
This is the get sources stage:
I would recommend adding the exact path to where the docker file resides on your repository .
Dockerfile: subpath/Dockerfile`
You're misusing this absolute path, both within the dockerfile and in the docker build task:
/home/vsts/work/1/s/
That is a path that exists on the build agent (not within the dockerfile) - but it may or may not exist on any given pipeline run. If the agent happens to use work directory 2, or 3, or any other number, then your path will be invalid. If you want to run this pipeline on a different type of agent, then your path will be invalid.
If you want to use a dockerfile in your checked out code, then you should do so by using a relative path (based on the root of your code repository), for example:
buildinfo/docker/Dockerfile
Note: that was just an example, to show the kind of path you should use; here you should be using the actual relative path in your actual code repo.
I am trying to use docker hub to automatically build something that builds fine locally. It fails saying:
Build process failed: stat /var/lib/docker/aufs/mnt/1be9db483fa6f3de2596b5261e7c450de8df503185e579278396f14ba179c257/bin/run.sh: not a directory
You can view the build itself here:
https://hub.docker.com/r/zbyte64/rethinkdb-tlsproxy/builds/bjclhq33kgwxxvn6nbfsgyh/
run.sh is in the same directory as Dockerfile, it seems the build path on dockerhub is different then where it stores the Dockerfile.
I have tried the following variations:
COPY run.sh /bin
ADD ./run.sh /bin
The COPY command (on Dockerhub's Docker version) expects the target file on the right hand side, not just the target directory. The following command should work for you even on Dockerhub.
COPY run.sh /bin/run.sh
Or if you want to use ADD, include the trailing slash.
ADD ./run.sh /bin/
What is actually happening? From https://docs.docker.com/engine/reference/builder/#add :
ADD src dest
"If dest does not end with a trailing slash, it will be considered a regular file and the contents of src will be written at dest."
Without the trailing slash on /bin, it expects run.sh to be a directory being copied to directory /bin.
I don't know why, but dockerhub wants the first argument of COPY or ADD to be a directory - not a file. I am running Docker 1.9.1 locally and that is not the case. I switched the Dockerfile to copy a resource directory instead of individual files and things started to work.