I have springrestapi project setup in my local with Dockerfile and docker-compose.yml file successfully running. Now I have added my api tests as part of this project inside the same repository by adding a new directory called in-memory-tests.
in-memory-tests directory has Dockerfile in it. This Dockerfile has commands to copy to image. when i run docker-compose.yml file. its giving below error.
[+] Running 0/1
⠿ testserv1 Error 5.1s
[+] Building 3.1s (8/10)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/maven:3.6.0-jdk-8-alpine 3.0s
=> CACHED [1/6] FROM docker.io/library/maven:3.6.0-jdk-8-alpine#sha256:c1439df43e994b9df98063458e704384b85914c8bef4c1de22f992f51dcc2d79 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 879B 0.0s
=> CACHED [2/6] COPY src /app/src 0.0s
=> ERROR [3/6] COPY testng.xml /app/ 0.0s
=> ERROR [4/6] COPY reports/testreport.html /app/reports/ 0.0s
[3/6] COPY testng.xml /app/:
[4/6] COPY reports/testreport.html /app/reports/:
failed to solve: failed to compute cache key: "/reports/testreport.html" not found: not found
Github repo link
2: []
2https://github.com/aamirsuhailo1/SpringRestAPIsOnDocker/tree/testframework_addition
Got resolved after adding
context: ./in-memory-tests/ and removing dockerfile: in-memory-tests/Dockerfile
You didn't set a build context in docker-compose.yml > testserv1 > build. If you provide a dockerfile property you must also set the context.
Alternatively you can just set the build property, to the directory that contains a Dockerfile, in your case build: . should suffice, as the docker-compose.yml is in the same directory as the Dockerfile.
Related
Let's say, I have this easy docker-compose.yml:
services:
foo:
container_name: bar
build: .
for the sake of completeness, I also want to share that simple Dockerfile:
FROM ubuntu:20.04
My folder structure is
temp
|- docker-compose.yml
|- Dockerfile
When I build the container with docker compose build, it gives no errors:
[+] Building 0.1s (5/5) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 31B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:20.04 0.0s
=> CACHED [1/1] FROM docker.io/library/ubuntu:20.04 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:87da********************************************************bb35 0.0s
=> => naming to docker.io/library/temp-foo 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
The outpot of that is identical to docker build . -t foo. When I run it with docker run -dt --name bar foo.
When I now issue docker compose up, I get bar exited with code 0:
[+] Running 2/2
- Network temp_default Created 0.0s
- Container bar Created 1.9s
Attaching to bar
bar exited with code 0
How is this possible or even make sense. Shouldn't both fail or work?
I can share the Dockerfile if needed, it's close to that one.
I'm following this docker tutorial for aspnet core. I built 1 aspnet core template project with swagger and it works fine. I have a problem with the docker file they instruct. Can someone help me.Tks.
Docs:https://docs.docker.com/samples/dotnetcore/
My repository : https://github.com/ThanhDeveloper/WebApplicationAspNetCoreTemplate/tree/DockerIntegration
Error when run command docker build -t abc .
I tried to change engine/examples with ../AspNetCoreTemplate ./ or ./AspNetCoreTemplate ./ but it didn't fix the error
nguyenthanh#MacBook-Pro-cua-Nguyen AspNetCoreTemplate % docker build -t abc .
[+] Building 0.4s (12/14)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 477B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:5.0 0.3s
=> [internal] load metadata for mcr.microsoft.com/dotnet/sdk:5.0 0.3s
=> [build-env 1/6] FROM mcr.microsoft.com/dotnet/sdk:5.0#sha256:3ca1a372ff025d1f84bb2bef7dbb7c284ea3b49e00bcd0047336b9bca9f8dfb7 0.0s
=> [stage-1 1/3] FROM mcr.microsoft.com/dotnet/aspnet:5.0#sha256:ca2e100d2c30490f7cb34ab737bc33e9bd7e533446f6c3356c082caccae7be1a 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 47B 0.0s
=> CACHED [build-env 2/6] WORKDIR /app 0.0s
=> CACHED [stage-1 2/3] WORKDIR /app 0.0s
=> CANCELED [build-env 3/6] COPY *.csproj ./ 0.0s
=> CACHED [build-env 4/6] RUN dotnet restore 0.0s
=> ERROR [build-env 5/6] COPY ../engine/examples ./ 0.0s
------
> [build-env 5/6] COPY ../engine/examples ./:
------
failed to compute cache key: "/engine/examples" not found: not found
You cannot copy from outside the build context. So COPY ../engine/examples ./ is failing because docker cannot traverse the ../ to go up a level.
All files you want to copy must be accessible from the within the docker context (. in this case)
I'm having trouble building docker containers on an Apple M1
The project uses sdk 2.2 which is incompatible with arm64 architecture. So I changed the sdk and aspnet cores to 2.2-alpine3.8 and they seem to build ok but the process fails when it needs to publish
The docker file:
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-alpine3.8 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY . .
RUN dotnet publish src/admin/MyContainer.Admin.csproj -c Release -o ./publish
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-alpine3.8
WORKDIR /app
COPY --from=build-env /app/src/admin/publish .
# Copy script that allows waiting for the database on docker-compose
# As referenced here https://docs.docker.com/compose/startup-order/
# This was done because admin starts up very quickly on e2e env
# and the sqlserver container wasn't getting ready fast enough
COPY --from=build-env /app/docker-wait-for-it.sh .
EXPOSE 80
CMD ["dotnet", "MyContainer.Admin.dll"]
the build command I'm using is:
docker buildx build --platform linux/arm64/v8 -t MyContainer.azurecr.io/admin-api-web:development ./backend -f ./backend/Admin.Api.Web.Dockerfile
and the log output is:
[+] Building 0.5s (11/13)
=> [internal] load build definition from Admin.Api.Web.Dockerfile 0.0s
=> => transferring dockerfile: 46B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/core/aspnet:2.2-alpine3.8 0.1s
=> [internal] load metadata for mcr.microsoft.com/dotnet/core/sdk:2.2-alpine3.8 0.1s
=> [build-env 1/4] FROM mcr.microsoft.com/dotnet/core/sdk:2.2-alpine3.8#sha256:1299ac0379146c1de7b588196727dbd56eace3abfbdd4321c547c9ff4a18a2f7 0.0s
=> => resolve mcr.microsoft.com/dotnet/core/sdk:2.2-alpine3.8#sha256:1299ac0379146c1de7b588196727dbd56eace3abfbdd4321c547c9ff4a18a2f7 0.0s
=> [stage-1 1/4] FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-alpine3.8#sha256:4d6e528f4c09c55804b6032ecc5d60565a3ee16f68bb08d2cf337dff99cdb8c3 0.0s
=> => resolve mcr.microsoft.com/dotnet/core/aspnet:2.2-alpine3.8#sha256:4d6e528f4c09c55804b6032ecc5d60565a3ee16f68bb08d2cf337dff99cdb8c3 0.0s
=> [internal] load build context 0.2s
=> => transferring context: 473.91kB 0.1s
=> CACHED [stage-1 2/4] WORKDIR /app 0.0s
=> CACHED [build-env 2/4] WORKDIR /app 0.0s
=> CACHED [build-env 3/4] COPY . . 0.0s
=> ERROR [build-env 4/4] RUN dotnet publish src/admin/MyContainer.Admin.csproj -c Release -o ./publish 0.1s
------
> [build-env 4/4] RUN dotnet publish src/admin/MyContainer.Admin.csproj -c Release -o ./publish:
#11 0.127 Failed to resolve full path of the current executable [/proc/self/exe]
I've tried with different platforms on the --platform flag and without any specified as well... If I try to build with core 2.2 I get this output:
[+] Building 0.5s (4/4) FINISHED
=> [internal] load build definition from Admin.Api.Web.Dockerfile 0.0s
=> => transferring dockerfile: 745B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> ERROR [internal] load metadata for mcr.microsoft.com/dotnet/core/aspnet:2.2 0.4s
=> CANCELED [internal] load metadata for mcr.microsoft.com/dotnet/core/sdk:2.2 0.4s
------
> [internal] load metadata for mcr.microsoft.com/dotnet/core/aspnet:2.2:
------
error: failed to solve: failed to solve with frontend dockerfile.v0: failed to create LLB definition: no match for platform in manifest sha256:08xxx: not found
Which I've found out to be because core 2.2 has no support form arm64. But this file builds without any errors on an Intel MacBook but with M1 I can't get past the build error. Any ideas?
This is not an answer but a followup to the problem,
which might shed some more light on the issue.
I'm using aspnet:6 and it passes the build.
The problem later on is that the runnable .dll throws
cannot execute binary file: Exec format error
which seems to be a platform issue, using Mac with an M1 Silicon chipset.
I have no issue with other docker images that are made for linux/amd64
The Docker daemon seems to deal with this fine (having installed Rosetta2 and the Latest Docker Desktop for M1)
https://docs.docker.com/desktop/mac/apple-silicon/
Have you managed to resolve the issue and execute the dll?
I have a test automation project which gets uses the code built as part of jar file and that jar gets invoked via bat file. All these files are stored within my project folder.
contents of my Docker file:
FROM maven:3.8.1-adoptopenjdk-11
#WORKDIR C:/Work/Kickstart_TEM/Prefs
COPY Prefs /home/Prefs
COPY KickStart.jar /home/Prefs/KickStart.jar
CMD home\prefs\run.bat && cmd
docker build generates following output
[+] Building 0.3s (8/8) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 210B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/maven:3.8.1-adoptopenjdk-11 0.0s
=> [1/3] FROM docker.io/library/maven:3.8.1-adoptopenjdk-11 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 390B 0.0s
=> CACHED [2/3] COPY Prefs /home/Prefs 0.0s
=> CACHED [3/3] COPY KickStart.jar /home/Prefs/KickStart.jar 0.0s
=> exporting to image 0.1s
=> => exporting layers 0.0s
=> => writing image sha256:4c878e8a895b2fad307e00f1b2fb5c9b5df7dc630e87414230d1989b75a5ee17 0.0s
=> => naming to docker.io/library/demo2
Docker run generates following error:
PS C:\Work\Docker_POC> docker run -i -p 4044:4044 demo2
/bin/sh: 1: homeprefsrun.bat: not found
My containers stops right away, so I am not even able to figure out if my files and folders got copied successfully or not. And I am unsure of how to resolve this error.
First of all, you're trying to run a batch script under Linux (the docker image you're using determines this).
In general, your CMD statement should look like CMD ["/bin/sh", "-c", "/home/Prefs/run.sh && cmd"] (although I'm not sure what cmd is and why you want to run it)
You should convert this batch script (run.bat) to a shell script. Also, there is a difference between home and /home and filenames are case-sensitive (thus it's Prefs and not prefs).
Relatively new to Docker and Compose, but I have read every letter of the Docker Compose documentation, and unsuccessfully bounced around SO for hours, with no resolution to the above question.
I have an (example) directory with the following files:
./Dockerfile:
# syntax=docker/dockerfile:1
ARG CUSTOM_NODE_VERSION
FROM node:$CUSTOM_NODE_VERSION
ARG CUSTOM_NODE_VERSION
ARG HELLO
RUN echo "HELLO: -> $HELLO"
RUN echo "NODE_VERSION -> $NODE_VERSION"
RUN echo "CUSTOM_NODE_VERSION -> $CUSTOM_NODE_VERSION"
./docker-compose.yml:
version: "3.8"
services:
test:
build:
context: .
dockerfile: Dockerfile
args:
CUSTOM_NODE_VERSION: alpine
HELLO: 5
What I want is for docker compose build to use the args specified in the docker-compose.yml file, but it doesn't:
> docker compose build test
[+] Building 0.8s (4/4) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> resolve image config for docker.io/docker/dockerfile:1 0.5s
=> CACHED docker-image://docker.io/docker/dockerfile:1#sha256:e2a8561e419ab1ba6b2fe6cbdf49fd92b95912df1cf7d313c3e2 0.0s
failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = failed to create LLB definition: failed to parse stage name "node:": invalid reference format
But run works fine:
docker compose run test
[+] Running 1/1
⠿ Network compose-args_default Created 4.3s
[+] Building 3.1s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> resolve image config for docker.io/docker/dockerfile:1 0.5s
=> CACHED docker-image://docker.io/docker/dockerfile:1#sha256:e2a8561e419ab1ba6b2fe6cbdf49fd92b95912df1cf7d313c3e2 0.0s
=> [internal] load metadata for docker.io/library/node:alpine 1.0s
=> CACHED [1/4] FROM docker.io/library/node:alpine#sha256:f372a9ffcec27159dc9623bad29997a1b61eafbb145dbf4f7a64568b 0.0s
=> [2/4] RUN echo "HELLO: -> 5" 0.5s
=> [3/4] RUN echo "NODE_VERSION -> 16.3.0" 0.3s
=> [4/4] RUN echo "CUSTOM_NODE_VERSION -> alpine" 0.5s
=> exporting to image 0.1s
=> => exporting layers 0.0s
=> => writing image sha256:e61653277599e3555b67c1a50699dd83d5c1ed1a93fe8a1a16529c6ec20e3e31 0.0s
=> => naming to docker.io/library/compose-args_test
This is all the more baffling to me because, per the Compose docs:
args
Add build arguments, which are environment variables accessible only during the build process.
Any help is much appreciated 🙏🏻
Build args were only recently added to compose-cli. Most likely that change hasn't reached the version of docker compose you're running. You can use docker-compose build (with a -) until this feature reaches your install.