Am new to Docker technologies, I have build an executable file in Visual Studio 2015 on Windows 10 machine.
Am looking to dockerize this executable file. I have build an Image and Container but the exe file is not being execute.
Here is my work so far:
Docker file:
FROM microsoft/aspnetcore:1.1
COPY . /app
WORKDIR /app
ENTRYPOINT ["dotnet","Controller.exe"]
CMD ["Controller.exe","RUN"]
Command used to create Image:
docker build -t imagename:version
Command used to create controller:
docker run -it --name Controller_name Image_ID run
Am trying to start the controller, but the controller is not starting
I have performed docker logs and here is the information in the log file.
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\app'.
Related
I am new to Docker. I created a Web API using ASP.Net Core using Visual Studio 2019 as well as in VS Code. It works fine. Then I added docker support and added Dockerfile with default values.
When I try to build the docker image, it fails in Visual Studio 2019 as well as in VS Code.
However, If I try to run the Docker image using the Visual Studio 2019 provided option (where I can select docker as run), then the image gets created.
But when I run the build command in Visual Studio 2019 or VS Code i.e.
docker build -f ./Dockerfile --force-rm -t mytestapp:dev ..
it throws following error<br>
=> ERROR [build 3/7] COPY [myTestApp.csproj, ./]
Content of my docker file is given below
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["myTestApp.csproj", "./"]
RUN dotnet restore "myTestApp.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "myTestApp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "myTestApp.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "myTestApp.dll"]
The project structure picture is also attached:
A simple docker build command cannot work with the default Dockerfiles created by Visual Studio because the paths are specified relative to the root of the solution, and not the root of the project.
You can inspect the build output from VS to determine how it builds the image (simplified version):
docker build
-f "PROJECT_PATH\Dockerfile"
-t IMAGE_NAME:dev
"SOLUTION_PATH"
As you can see, it builds using the Dockerfile in the project folder (-f), but from the solution folder.
I guess they did it because it has the advantage of keeping each Dockerfile in its own project folder, while letting you reference resources outside that folder using more consistent solution-based paths. Apart from that, it's pretty annoying.
You can move the Dockefile to the solution folder and leave it unchanged, but then the Docker features in VS will stop working as expected. Or you can adopt the VS convention and adapt your scripts accordingly.
Try running the command from the parent folder, you can specify the path to the Dockerfile using the -f flag.
cd ..
docker build -t imagename:tag -f ProjectDir/Dockerfile .
Docker copy's the .csproj and other files from the current location on the host machine, so if you say:
COPY ["myTestApp.csproj", "./"]
Make sure you are in the right directory on the host machine. The Dockerfile created by Docker Support is not always ideal for building images if you use for example other project references but can be a good base.
Run this from your Solution root:
docker build . -f [ProjectDir]\Dockerfile
Answer from *#axtc*k worked for me. The only change required to make it work was to remove the slash:
cd ..
docker build -t imagename:tag -f ProjectDir/Dockerfile .
Use docker-compose to easily create and tear down your setup.
Step 1: Save code below as docker-compose.yml one directory higher than your Dockerfile (same path as your project's .sln file):
version: '3'
services:
web:
build:
context: .
dockerfile: [PROJECTNAME]\Dockerfile
ports:
- "5000:80"
networks:
- aspcore-network
sql-server:
image: mcr.microsoft.com/mssql/server
networks:
- aspcore-network
networks:
aspcore-network:
driver: bridge
Step 2: Add additional services (MYSQL/REDIS/ETC)
Step 3: Open terminal to docker-compose.yml location
Step 4: Run docker-compose build then docker-compose up -d
Step 5: When done run docker-compose down
Remove the .(dot) you included at WORKDIR "/src/."
I solved this issue by providing the absolute path to the docker command.
Instead, go to the parent directory, with the .sln file and use the docker -f option to specify the Dockerfile to use in the subfolder:
cd \CoreDockerAPI
docker build -f CoreDockerAPI\Dockerfile --force-rm -t myfirstimage .
docker run -it myfirstimage
Here are the steps I used to solve this problem :
I checked Enable Docker while creating my .NET 5 Web API Project.
For Docker OS, I chose Linux.
Then I opened a terminal, navigated to the directory where my project is and typed the following command : docker build -f Movie.WebAPI\Dockerfile --force-rm -t movie-api:v1 .
Which gave the following results :
for path
for result
continuation of the result
As the last step, I ran this command : docker run -it --rm -p 8080:80 movie-api:v1
Which created the container image.
Now movie-api appears when I type docker images.
I need to find out how a simple C console application will work in Ubuntu. I have Windows installed on my machine. In order not to run the virtual machine, I decided to use Docker, it seems to be intended for this purpose. But I don't understand how to do it.
I downloaded and installed Docker Toolbox from here https://docs.docker.com/toolbox/toolbox_install_windows/
Then I run Docker Quickstart Terminal and write $ docker run ubuntu gcc-o hello hello.c there and get an error:
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"gcc\": executable file not found in $PATH": unknown.
hello.c - source code in C that prints "hello world" to the screen. This file is located in the same directory as docker.exe
Other commands from ubuntu, such as $ docker run ubuntu echo 'Hello world' work
I'm new to Docker. Am I using Docker as intended? If so, why doesn't it work ?
Create a file and name it dockerfile next to your hello.c. Your folder should look like this
- tempdir
|_ hello.c
|_ dockerfile
In the dockerfile file you will give instructions to docker on how to build your container image. Paste into dockerfile theses instructions
FROM gcc
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
RUN gcc -o myapp hello.c
CMD ["./myapp"]
Then you can build your image using this command
C:\tempdir> docker build . --tag helloworldfromgcc
note: make sure you are in the dockerfile folder
and last, run your container :)
docker run helloworldfromgcc
Explanations on the dockerfile instructions
# Here you are telling docker that as a base image it should use gcc.
# That image will be downloaded from here: https://hub.docker.com/_/gcc
# that gcc image has the linux kernel and gcc installed on it (not accurate, but good enough to understand)
FROM gcc
# This line will copy your files from your machine disk to the container virtual disk.
# This means the hello.c file will be copied into /usr/src/myapp folder inside the container
COPY . /usr/src/myapp
# This is like doing 'cd /usr/src/myapp'
WORKDIR /usr/src/myapp
# You know this one :) just call gcc with the standard params
RUN gcc -o myapp hello.c
# CMD differs from run because it will be executed when you run the container, and not when you are building the image
CMD ["./myapp"]
I am trying to build a docker image using the dockerfile, my purpose is to copy a file into a specific folder when i run the "docker run" command!
this my dockerfile code:
FROM openjdk:7
MAINTAINER MyPerson
WORKDIR /usr/src/myapp
ENTRYPOINT ["cp"]
CMD ["/usr/src/myapp"]
CMD ls /usr/src/myapp
After building my image without any error (using the docker build command), i tried to run my new image:
docker run myjavaimage MainClass.java
i got this error: ** cp: missing destination file operand after ‘MainClass.java’ **
How can i resolve this? thx
I think you want this Dockerfile:
FROM openjdk:7
WORKDIR /usr/src/myapp
COPY MainClass.java .
RUN javac MainClass.java
ENV CLASSPATH=/usr/src/myapp
CMD java MainClass
When you docker build this image, it COPYs your Java source file from your local directory into the image, compiles it, and sets some metadata telling the JVM where to find the resulting .class files. Then when you launch the container, it will run the single application you've packaged there.
It's common enough to use a higher-level build tool like Maven or Gradle to compile multiple files into a single .jar file. Make sure to COPY all of the source files you need in before running the build. In Java it seems to be common to build the .jar file outside of Docker and just COPY that in without needing a JDK, and that's a reasonable path too.
In the Dockerfile you show, Docker combines ENTRYPOINT and CMD into a single command and runs that command as the single main process of the container. If you provide a command of some sort at the docker run command, that overrides CMD but does not override ENTRYPOINT. You only get one ENTRYPOINT and one CMD, and the last one in the Dockerfile wins. So you're trying to run container processes like
# What's in the Dockerfile
cp /bin/sh -c "ls /usr/src/myapp"
# Via your docker run command
cp MainClass.java
As #QuintenScheppermans suggests in their answer you can use a docker run -v option to inject the file at run time, but this will happen after commands like RUN javac have already happened. You don't really want a workflow where the entire application gets rebuilt every time you docker run the container. Build the image during docker build time, or before.
Two things.
You have used CMD twice.
CMD can only be used once, think of it as the purpose of your docker image. Every time a container is run, it will always execute CMD if you want multiple commands, you should use RUN and then lastly, used CMD
FROM openjdk:
MAINTAINER MyPerson
WORKDIR /usr/src/
ENTRYPOINT ["cp"]
RUN /usr/src/myapp
RUN ls /usr/src/myapp
Copying stuff into image
There is a simple command COPY the syntax being COPY <from-here> <to-here>
Seems like you want to run myjavaimage so what you will do is
COPY /path/to/myjavaimage /myjavaimage
CMD myjavaimage MainClass.java
Where you see the arrows, I've just written dummy code. Replace that with the correct code.
Also, your Dockerfile is badly created.
ENTRYPOINT -> not sure why you'd do "cp", but it's an actual entrypoint. Could point to the root dir of your project or to an app that will be run.
Don't understand why you want to do ls /usr/src/myapp but if you do want to do it, use RUN and not CMD
Lastly,
Best way to debug docker containers are in interactive mode. That means ssh'ing in to your container, have a look around, run code, and see what is the problem.
Run this: docker run -it <image-name> /bin/bash and then have a look inside and it's usually the best way to see what causes issues.
This stackoverflow page perfectly answers your question.
COPY foo.txt /data/foo.txt
# where foo.txt is the relative path on host
# and /data/foo.txt is the absolute path in the image
If you need to mount a file when running the command:
docker run --name=foo -d -v ~/foo.txt:/data/foo.txt -p 80:80 image_name
I'm trying to build an image of a .netcore v2.2 WebAPI app from docker file. But I'm getting a "no such file or directory" error while I try to build the image using following command:
docker build -t helloworld .
I have both microsoft/dotnet "latest" and "2.2-aspnetcore-runtime" base images installed in my machine.
Here's my docker file
FROM microsoft/dotnet
RUN mkdir /app
COPY ./bin/Release/netcoreapp2.2 /app
WORKDIR /app
ENTRYPOINT ["dotnet", "/app/HelloWorld.dll"]
# ASP.NET Core: Kestrel should listen on all IPs
ENV ASPNETCORE_URLS="http://0.0.0.0:5000"
Here's the folder structure of my solution (I tried the command inside the src):
Here's the output directory
Here's the full error details from the docker:
COPY failed: stat /var/lib/docker/tmp/docker-builder896068669/bin/Release/netcoreapp2.2: no such file or directory
you may change ./bin/Release/netcoreapp2.2 to ./bin/release/netcoreapp2.2
folder names are case sensitive
It seems the file ./bin/Release/netcoreapp2.2/publish does not exists on the machine on which you are running docker build
When you run docker build -t helloworld . it will copy all the file in . (i.e. the current directory from which you run the command) to the build context which will then be used when running COPY instructions, so you need to make sure you are running your command from the proper directory where files will be available to COPY
You can also run the same command from another directory by specifying the path to be used as build context such as docker build -t helloworld /path/to/my/dir
I want to build a docker image of a composer from this page composer:latest and taking exactly this Dockerfile
but when I do this in console:
$ wget -O Dockerfile https://raw.githubusercontent.com/composer/docker/edf4f0abf50da5d967408849434b9053a195b65f/1.7/Dockerfile
$ docker build -t mycomposer:latest .
i got this build error:
Step 9/12 : COPY docker-entrypoint.sh /docker-entrypoint.sh COPY
failed: stat
/var/lib/docker/tmp/docker-builder787686173/docker-entrypoint.sh: no
such file or directory
How come I have any error building from official Dockerfile?
This way works:
$ docker pull composer:latest
but I need to build an image basing on a local Dockerfile instead of just pulling it.
The command
COPY docker-entrypoint.sh /docker-entrypoint.sh
in the Dockerfile tries to copy the file docker-entrypoint.sh from your current directory.
However you have only downloaded the Dockerfile.
If you visit the actual directory on the repository you will notice another file entitled
docker-entrypoint.sh. If you download this file too and place it in the same directory
as the Dockerfile the image will be built without errors.