My Dockerfile is
FROM alpine
RUN apk update && apk add --no-cache curl ca-certificates unzip coreutils bash
WORKDIR /
COPY build/current/database .
COPY build/current/dist .
COPY build/current/queries .
COPY build/current/resources .
COPY build/current/storage .
COPY build/current/.env .
COPY build/current/app .
ENTRYPOINT ["./app artisan migrate"]
CMD ["./app"]
But it’s unable to run and gives following error:
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "./app artisan migrate": stat ./app artisan migrate: no such file or directory: unknown
When using following,
FROM alpine
RUN apk update && apk add --no-cache curl ca-certificates unzip coreutils bash
WORKDIR /
COPY build/current/database .
COPY build/current/dist .
COPY build/current/queries .
COPY build/current/resources .
COPY build/current/storage .
COPY build/current/.env .
COPY build/current/app .
ENTRYPOINT ./app artisan migrate
CMD ./app
I get error in docker logs
/bin/sh: line 0: ./app: not found
/bin/sh: line 0: ./app: not found
/bin/sh: line 0: ./app: not found
/bin/sh: line 0: ./app: not found
/bin/sh: line 0: ./app: not found
/bin/sh: line 0: ./app: not found
/bin/sh: line 0: ./app: not found
Please suggest there’s in mistake in my approach and suggest some way to fix the issue
2
Answers
When you
COPY
build/current/database
into your docker container, you are only copying the content of the directory/database
.In you case, you are copying all the content of your directories into the root of the container. In the end,
/database
doesn’t exists in the container. Same for the othersTo solve your issue, you can try to
COPY
the content ofbuild/current
into the container.Here is a Dockerfile you can try :
EDIT : I see you are trying to copy a build folder. A good practice is to build while you are creating the image. Not doing this can result in bugs due to a change of environment.
You can try something like this and see if it works :
There are multiple issues with your
Dockerfile
:Using
COPY <src> .
withWORKDIR /
will copy all files into the root directory of your image with clutters the root directory and may even conflict with existing files of the base image. You should really useWORKDIR /app
orWORKDIR /code
or something like that.The
COPY build/current/database .
directive etc. will only copy the directory contents, not the directory itself, i.e., the contained file get copied directly into/
and not into a subdirectory/database/
See the
COPY
documentation on this:As others already pointed out in the comments: if
./app
is a binary you need to make sure that all linked libraries are also available within the image.Instead of building the binary on the host I would recommend you to rather use multi-stage builds.
ENTRYPOINT ["./app artisan migrate"]
results in an error:This because you are using the exec form of
ENTRYPOINT
where the first string in the array is the name of the executable and all following strings are the arguments. But since you only used a one stringdocker
is trying to execute a single file named "./app artisan migrate
", i.e., a file with two spaces in it – which does not exist.Instead what you should have used is
CMD
does not do what you seem to expect:This does not first execute the migrations and then start
./app
!Instead the provided
CMD
is added as arguments to theENTRYPOINT
, i.e., whatdocker
is executing to start your container isRead the documentation on
ENTRYPOINT
andCMD
!If you want to ensure that
./app artisan migrate
is always run before any provided command, you can use a custom entrypoint script. For example:and use it with
With this by default
docker
will run./app
after the migrations and alternatively you can specify another command on the command line: