docker-compose failed to solve: rpc error: code = Unknown desc - docker

I have a problem. I want to build a docker-compose file from tfserving but unfortunately I got the following error failed to solve: rpc error: code = Unknown desc. What is the problem? I am using Windows.
CMD
docker compose up -d
Dockerfile
FROM tensorflow/serving
EXPOSE 8601
docker-compose.yml
version: '3'
services:
tfserving:
container_name: tfserving
build: ..
ports:
- "8601:8601"
volumes:
- ./model.config:/models/model.config
- ../model:/models/model
environment:
- TENSORFLOW_SERVING_REST_API_PORT=8061
- TENSORFLOW_SERVING_MODEL_NAME=model
- TENSORFLOW_MODEL_BASE_PATH=/models/model/
entrypoint: [ "bash", "-c", "tensorflow_model_server --rest_api_port=8601 --allow_version_labels_for_unavailable_models --model_config_file=/models/model.config"]
Error
docker compose up -d
[+] Building 0.0s (2/2) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 2B 0.0s
=> CANCELED [internal] load .dockerignore 0.0s
=> => transferring context: 0.0s
failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount057242145/Dockerfile: no such file or directory
Dicrectory
|- tfserving
| |- docker-compose.yml
| |- Dockerfile
| |- model.config
|- model
| |- 1
| | |- ...
| |- 2
| | |- ...
|....

You have too many dots in your docker-compose's build(context) line:
version: '3'
services:
tfserving:
container_name: tfserving
build: .. <-- here, the correct one is the current folder .

Related

Can't run docker containers on remote host

I'm trying to run my php website with nginx server as docker containers on a remote server via ssh connection using docker compose
I used this commanddocker-compose -H ssh://<username>#<**.***.**.***> up -d
and got this error
[+] Building 0.0s (0/0)
[+] Building 0.0s (0/0)
[+] Building 8.0s (2/2) FINISHED
=> ERROR [internal] load build definition from Dockerfile 5.0s
=> CANCELED [internal] load .dockerignore 5.0s
------
> [internal] load build definition from Dockerfile:
------
failed to dial gRPC: command [ssh -l username-- **.***.**.*** docker system dial-stdio] has exited with exit status 1, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=
My Dockerfile:
FROM php:8.0.2-fpm
RUN apt-get update && apt-get install -y \
git \
curl \
zip \
vim \
unzip
WORKDIR /var/www
My docker-compose.yml
version: '3.8'
services:
app:
build:
context: ./
dockerfile: Dockerfile
container_name: programwithgio-app
restart: always
working_dir: /var/www/
volumes:
- ../src:/var/www
nginx:
image: nginx:1.19-alpine
container_name: programwithgio-nginx
restart: always
ports:
- 8000:80
volumes:
- ../src:/var/www
- ./nginx:/etc/nginx/conf.d

How to use locally built image in docker-compose file correctly?

I have multiple services that needs to use the same locally built image.
So I created a helper service which would build the image and all other services would depend on the builder service to ensure that image is built first.
Here's docker-compose.yml with only 2 services but in actual, I have around 20 services.
version: "3.5"
services:
api:
image: test-image # using the image built below
networks:
- mylab
depends_on:
- tests-container-builder
volumes:
- ./tests:/tests
command: pytest -v -p no:cacheprovider /tests/api.py
license-chrome:
image: test-image
networks:
- mylab
depends_on:
- tests-container-builder
volumes:
- ./tests:/tests
command: sh -c "/tests/health-check-script.sh && pytest -v -p no:cacheprovider -n=1 /tests/license.py"
tests-container-builder:
build:
context: .
dockerfile: ./tests/Dockerfile
target: test-env
image: test-image # this service builds the image
But when I build and run the container using
docker-compose up --build api; \
docker-compose up --scale license-chrome
I'm getting error like
ERROR: for mylab_visual_ner-chrome_1 no such image: sha256:ceff9945d8722c89331696aa33d88f84703e322fbb64c1ebaa8f83c6e19a4cfa: No such image: sha256:ceff9945d8722c89331696aa33d88f84703e322fbb64c1ebaa8f83c6e19a4cfa
ERROR: for visual_ner-chrome no such image: sha256:ceff9945d8722c89331696aa33d88f84703e322fbb64c1ebaa8f83c6e19a4cfa: No such image: sha256:ceff9945d8722c89331696aa33d88f84703e322fbb64c1ebaa8f83c6e19a4cfa
ERROR: The image for the service you're trying to recreate has been removed. If you continue, volume data could be lost. Consider backing up your data before continuing.
Continue with the new image? [yN]
It works fine if I remove the test-container-builder service and use build command inside all services.
Is it considered an anti-pattern to use a different service to build image?
What is the proper way to do this ?
I'd consider an absolutely-best-practice Compose setup to only contain long-running containers, and not containers you don't expect to actually run. In your case the "builder" container doesn't actually do anything and I wouldn't include it in the Compose setup. Conversely, build:ing a literally identical image from the same source code is all but free; Docker needs to scan the build context to determine that the two images are identical, but in the end you will just get two different names for the same physical image.
Taking #TheFool's suggestion to use YAML anchors to avoid repeating the build setup, I might write:
version: '3.8'
services:
api:
build: &build-definition
context: .
dockerfile: ./tests/Dockerfile
target: test-env # (can you avoid this?)
command: pytest -v -p no:cacheprovider /tests/api.py
license-chrome:
build: *build-definition
# (does the health check belong in an ENTRYPOINT wrapper in the image?)
command: sh -c "/tests/health-check-script.sh && pytest -v -p no:cacheprovider -n=1 /tests/license.py"
I've omitted unnecessary networks:, since Compose creates a perfectly usable network named default for you, and volumes:, since your code should generally be built into the image.
If you want to explicitly build the image and include it in the Compose setup (maybe you want to push it to a registry) then you need to manually docker-compose build the builder image, not any of the containers you're going to run. The Compose setup can look like
version: '3.8'
services:
api:
image: registry.example.com/my-name/test-image:${TAG:-latest}
command: pytest -v -p no:cacheprovider /tests/api.py
license-chrome:
image: registry.example.com/my-name/test-image:${TAG:-latest}
command: sh -c "/tests/health-check-script.sh && pytest -v -p no:cacheprovider -n=1 /tests/license.py"
tests-container-builder:
image: registry.example.com/my-name/test-image:${TAG:-latest}
build:
context: .
dockerfile: ./tests/Dockerfile
target: test-env
restart: "no"
command: exit 0
Compared to my previous Compose setup and your question, I make it explicit that the container should just exit immediately and not restart, and I use a registry-qualified name. depends_on: only affects the order in which containers start starting and doesn't include any dependencies on image builds.
If you're using this setup, you need to docker-compose build the builder "container" before you run the rest:
export TAG=20211124 # often useful to avoid ...:latest
docker-compose build test-container-builder # not "api"
# docker-compose push test-container-builder # if required
docker-compose up -d # could just launch specific containers
This is maybe not a real answer, but I have recreated your scenario, and it surprisingly works. I did expect it to fail if you only want to build the container that hasn't a build key in the config.
docker system prune -af # ensure we dont get confused with pre build images or chaching
docker-compose up --build two # try to run only service two
Compose file:
version: "3.9"
volumes:
data: null
services:
one:
image: foo
build:
context: ./
dockerfile: Dockerfile
target: stage1
command: sh -c 'sleep 5 && echo "one done"'
two:
image: foo
command: sh -c 'sleep 5 && echo "two done"'
volumes:
- data:/stuff
- ./test:/test
depends_on:
- one
Dockerfile
FROM busybox as stage1
RUN echo "Hello World"
FROM busybox
CMD sleep infinity
The output I am getting is the following. It may make sense because when reading the definition of the --build flag, Build images before starting containers., it sounds a bit like it doesn't care about what service you want to start. It just builds all images.
docker-compose up --build two
Creating network "test_default" with the default driver
Building one
[+] Building 3.3s (6/6) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 121B 0.0s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/busybox:latest 2.3s
=> [stage1 1/2] FROM docker.io/library/busybox#sha256:b5cfd4befc119a590ca1a81d6bb0fa1fb19f1fbeb 0.4s
=> => resolve docker.io/library/busybox#sha256:b5cfd4befc119a590ca1a81d6bb0fa1fb19f1fbebd0397f2 0.0s
=> => sha256:b5cfd4befc119a590ca1a81d6bb0fa1fb19f1fbebd0397f25fae164abe1e8a6a 2.29kB / 2.29kB 0.0s
=> => sha256:50e44504ea4f19f141118a8a8868e6c5bb9856efa33f2183f5ccea7ac62aacc9 527B / 527B 0.0s
=> => sha256:ffe9d497c32414b1c5cdad8178a85602ee72453082da2463f1dede592ac7d5af 1.46kB / 1.46kB 0.0s
=> => sha256:3cb635b06aa273034d7080e0242e4b6628c59347d6ddefff019bfd82f45aa7 772.78kB / 772.78kB 0.3s
=> => extracting sha256:3cb635b06aa273034d7080e0242e4b6628c59347d6ddefff019bfd82f45aa7d5 0.1s
=> [stage1 2/2] RUN echo "Hello World" 0.4s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:81893d72f6be148599854469098e9f8c80a73e28acd5991a1757033440d34e5c 0.0s
=> => naming to docker.io/library/foo 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Creating test_one_1 ... done
Creating test_two_1 ... done
Attaching to test_two_1
two_1 | two done
test_two_1 exited with code 0

docker-compose cannot attach container to network if full project name given

I am running docker desktop(version 4.0.1) in Mac and inside that I am trying my hand in docker compose file for a very simple rest api.
Below is my Dockerfile:
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8
COPY . /app
WORKDIR /app
RUN pip install -r ./requirements/requirements.txt
CMD uvicorn --host 0.0.0.0 application:app --reload
And below is my docker-compose.yml file:
version: '3'
services:
db:
image: mongo
ports:
- "27017:27017"
volumes:
- ./server_setup.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
container_name: server
web_app:
build:
dockerfile: Dockerfile
context: .
image: mongo-based-fastapi-app
depends_on:
- db
ports:
- "8000:8000"
volumes:
mongo_data:
When I am inside the project directory and run this command : docker-compose --project-directory . -f ./docker-compose.yml -p test up --build -d web_app everything works file .
However when I replace the command with the full path to the project like so : docker-compose --project-directory /Users/subhayanbhattacharya/Studies/HobbyProjects/mongo-book-store-fastapi -f /Users/subhayanbhattacharya/Studies/HobbyProjects/mongo-book-store-fastapi/docker-compose.yml -p /Users/subhayanbhattacharya/Studies/HobbyProjects/mongo-book-store-fastapi up --build -d web_app, I get the below error message:
[+] Building 2.9s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 221B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 79B 0.0s
=> [internal] load metadata for docker.io/tiangolo/uvicorn-gunicorn-fastapi:python3.8 2.4s
=> [auth] tiangolo/uvicorn-gunicorn-fastapi:pull token for registry-1.docker.io 0.0s
=> [internal] load build context 0.2s
=> => transferring context: 265.17kB 0.2s
=> [1/4] FROM docker.io/tiangolo/uvicorn-gunicorn-fastapi:python3.8#sha256:ff437138e8a38edb8f6070c8eefdd570faf1de4dbd0df644c7632160b2b62eb2 0.0s
=> CACHED [2/4] COPY . /app 0.0s
=> CACHED [3/4] WORKDIR /app 0.0s
=> CACHED [4/4] RUN pip install -r ./requirements/requirements.txt 0.0s
=> exporting to image 0.1s
=> => exporting layers 0.0s
=> => writing image sha256:5dd081b255c320871c1211985e25f3da664a1be9e5ce4340375213f3a2840ea0 0.0s
=> => naming to docker.io/library/mongo-based-fastapi-app 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
[+] Running 1/2
⠿ Network /users/subhayanbhattacharya/studies/hobbyprojects/mongo-book-store-fastapi_default Created 0.1s
⠙ Container server Creating 0.1s
Error response from daemon: container 3157afc2465fe3e8baf6db0aec875155ff62e3714296064794a003076e24aa93 is not connected to the network users/subhayanbhattacharya/studies/hobbyprojects/mongo-book-store-fastapi_default
Can someone please tell where I am going wrong ?
Many thanks in advance.

Can't build dockerfile with Pulumi

I'm trying to build a docker file with Pulumi. I have the following Pulumi code
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
imageName := "server"
_, err = docker.NewImage(ctx, imageName, &docker.ImageArgs{
ImageName: pulumi.Sprintf("gcr.io/gadic-310112/%s:latest", imageName),
SkipPush: pulumi.Bool(true),
Build: &docker.DockerBuildArgs{
Dockerfile: pulumi.String("Dockerfile"),
},
})
if err != nil {
return err
}
}
}
However, when I run pulumi preview I get the following error:
Diagnostics:
pulumi:pulumi:Stack (server-prod):
error: program failed: docker build -f Dockerfile . -t gcr.io/gadic-310112/server:latest failed with error: exit status 1
exit status 1
error: an unhandled error occurred: program exited with non-zero exit code: 1
docker:image:Image (server):
error: #1 [internal] load build definition from Dockerfile
#1 sha256:921a08a3c227abd8c3811effc689fa5319db237c32a4adf2b255007a51af9ef8
#1 transferring dockerfile: 2B 0.0s done
#1 DONE 0.0s
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount052159980/Dockerfile: no such file or directory
What's interesting is that it seems Pulumi is running docker build -f Dockerfile . -t gcr.io/gadic-310112/server:latest under the hood. And when I run that from my terminal it succeeds without any error.
❯❯❯ docker build -f Dockerfile . -t gcr.io/gadic-310112/server:latest
[+] Building 11.3s (16/18)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 1.87kB 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
....
It seems that Pulumi might be using a different working directory than the place where it's getting invoked from. Is that possible? Is there something else that might be going on?
I've noticed that if I don't include a Dockerfile in the DockerBuildArgs then the command generated by pulumi is docker build -f . -t gcr.io/gadic-310112/server:latest which is definitely incorrect. If I execute that command locally I get the following:
❮❮❮ docker build -f . -t gcr.io/gadic-310112/server:latest
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
EDIT: I also tried passing the absolute path to the folder containing my Dockerfile as the Context of the BuildArgs
Build: &docker.DockerBuildArgs{
Dockerfile: pulumi.String("Dockerfile"),
Context: pulumi.String("/Users/paymahn/gadic/server"),
},
and this still gets the same error as before, even though the underlying docker build command has an absolute path:
Diagnostics:
docker:image:Image (server):
error: #1 [internal] load build definition from Dockerfile
#1 sha256:16f11ab26c775f06385c0fde07864ed70b428d13662aa2be42823751fb5143f4
#1 transferring dockerfile: 2B 0.0s done
#1 DONE 0.1s
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount684750851/Dockerfile: no such file or directory
pulumi:pulumi:Stack (server-prod):
error: program failed: docker build -f Dockerfile /Users/paymahn/gadic/server -t gcr.io/gadic-310112/server:latest failed with error: exit status 1
exit status 1
error: an unhandled error occurred: program exited with non-zero exit code: 1
EDIT 2: Here's the layout of my files
/Users/paymahn/gadic/server/
infra/
main.go # this is the go program that pulumi runs
src/ # this is where the source code for my server lives
Dockerfile
Pulumi.yaml
Pulumi.prod.yaml # the pulumi stack config
go.sum
go.mod
.git/ # this is the root of my git repository
Your Pulumi projects builds inside your infra directory, not in the folder your Pulumi.yaml is in.
The Pulumi provider needs to know the path of the Dockerfile using the docker build context (more info about these here)
Adding the context should fix this:
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
imageName := "server"
_, err = docker.NewImage(ctx, imageName, &docker.ImageArgs{
ImageName: pulumi.Sprintf("gcr.io/gadic-310112/%s:latest", imageName),
SkipPush: pulumi.Bool(true),
Build: &docker.DockerBuildArgs{
Dockerfile: pulumi.String("Dockerfile"),
Context: "../", # note I'm adding the context here
},
})
if err != nil {
return err
}
}
}

Dockerfile Build Error: The system cannot find the path specified

C:\kafka> docker build Dockerfile
[+] Building 0.0s (1/2)
=> ERROR [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 63B 0.0s
------
> [internal] load build definition from Dockerfile:
------
failed to solve with frontend dockerfile.v0: failed to read dockerfile: error from sender: walk Dockerfile: The system cannot find the path specified.
Above is an example of the error I am getting and the command run.
My Dockerfile is named "Dockerfile" as I have read on many answers but still no resolve.
My Dockerfile is also within the directory I am in.
To build a docker image:
cd /path/where/docker_file/lives
docker build .
Above is same as:
docker build -f Dockerfile .
You need to specify Dockerfile name only if it is not default:
cd /path/where/docker_file/lives
docker build -f Dockerfile.modified .

Resources