Docker COPY index.html throws error in laravel project - laravel

My Docker file contents:
FROM nginx:1.18 COPY index.html /usr/share/nginx/html
Gitlab Runner log error message:
Step 2/2 : COPY index.html /usr/share/nginx/html COPY failed: file not found in build context or excluded by .dockerignore: stat index.html: file does not exist
Setup: It is laravel app. So no index.html file exists…
I have no idea how to proceed…
Thx!

As suggested by sytech I simply needed to delete COPY line.
Because, in my case, I don't need to copy anything. Line was taken from tutorial of setting Gitlab runner.

Related

Copy folder from Windows host OS into Docker image using COPY in Docker file

I want to copy folder D:\test from my host OS (Windows) to my docker image.
My Docker file is D:\Programs>
Docker file
FROM mcr.microsoft.com/windows/servercore:ltsc2019
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN mkdir root
RUN cd root
WORKDIR /root
RUN mkdir test
COPY D:/test to /root/test
#USING 'COPY' here instead of 'ADD' because of https://stackoverflow.com/questions/24958140/what-is-the-difference-between-the-copy-and-add-commands-in-a-dockerfile
From folder D:\Programs> I run command docker build . -t test
But I get error:
COPY failed: file not found in build context or excluded by .dockerignore: stat test: file does not exist
I tried commands COPY D:/test to /root/test and COPY ./test to /root/test
I know this error occurs because the path I copy from has to be relative from the build context (the . in docker build .). It cannot be an arbitrary path on the system outside of the build context.
I thought by using . I'd be in context D:\ from my build context D:\Programs>, but I guess not. What should my COPY command look like?
I checked here already:
https://forums.docker.com/t/copy-files-from-windows-host-to-ubuntu-container/28757
Dockerfile COPY from a Windows file system to a docker container
Dockerfile: Copy directory from Windows host to docker container
UPDATE 1
I placed the test folder in D:\Programs where my Dockerfile also resides, so I now have structure:
D:\Programs
\Test
Dockerfile
I then ran the build command again where I tried COPY test to /root/test and COPY ./test to /root/test, but both fail with the same aforementioned error.
I assume you've only added to in COPY D:/test to /root/test for abbreviation but I recommend checking that anyway.
If you really need what's in D:/Programs and can't move it to a folder inside the current build context there are two general options as I see it:
changing the build context - I'd suggest setting the build context as D:/ and adding every folder in the D:/ directory other than Programs to the .dockerignore file, then you can reference the Dockerfile from some subdirectory somewhere in D:/ and copy your files at build time as you wanted
creating a bind mount in runtime - you can map the D:/Programs directory to a folder inside the container (/my-programs) at runtime then copy the files from that folder to /root/test or just use the bind mount folder (/my-programs)
If in the future it will be available to use bind mounts in build time you'd be able to use the second option while creating the docker image
The only way I know how to do this is to change the dockerfile location during build, keeping the copied folder in context.
As below:
'test' folder located at D:/test
Set dockerfile COPY command as such:
COPY test /root/test
Say dockerfile is at D:/Programs/dockerfile
Navigate to D:/ in CLI
docker build -f ./Programs/dockerfile .
The . keeps the "test" folder in the build context. As far as I know, you cannot go to a parent directory etc. with docker build, so instead you want to stay in the parent folder and go down to the dockerfile.
If you run the docker build ... from D:\Programs that folder is the docker build context. All files used in the Dockerfile must be there.
d:\files is outside d:\programs, so it will be never be found.
You need to copy files content to the places where you run the command and you can use this copy line
COPY samplefile1.txt /root/test

cannot create custom folders in docker logstash image based container

i'm using logstash image and i have some ruby scripts that are located in the same directory as my dockerfile.
my goal is to create a script folder, and copy my scripts to it.
my problem is that when i access to the container instance, the folder is not created and no ruby file exist.
this is my dockerfile
FROM docker.elastic.co/logstash/logstash:${ELK_VERSION}
USER root
WORKDIR /usr/share/logstash
RUN mkdir scripts
COPY ./scripts/*.rb scripts
thanks in advance.
EDIT 1:
this is the files structure

Golang Server 404 on Static Pages

I am working on a compiled Golang server that displays a home page, and upload page, and a file repository. It can also upload a file to its backend. The goal is to put this into a container and use it.
Code: https://github.com/thatMacAdmin/go-webserver
If I do the following on my local machine:
go run webserver.go
Then it works as expected. The page in /static/index.html loads. I can upload files etc (as long as the repo exists in the right location). However when I build this and put it in a docker container, the repo file list works, and the upload endpoint exists, however the two static html pages get 404 errors.
What am I doing wrong? Why doesn't http://localhost:8080 work to display my home page in the container but it does work with the go run method?
Thanks,
Ed
The issue here was that Docker uses / as its relative path unless you tell it otherwise. In this instance my code expected the relative path to be where my server binary was located. In my case:
/server
Setting the WORKDIR option correctly in my Dockerfile fixed this.
Example:
FROM alpine:latest
RUN mkdir -p /server/static
COPY webserver /server
COPY static /server/static
WORKDIR /server
ENTRYPOINT ["/server/webserver"]
EXPOSE 8080
The static files are not automatically included in your binary. So you need to make sure that the running application working directory (even if it is running within a docker container) contains the folder "static" and its files. Otherwise the file is not found and you get an 404.
One alternative to this is to compile the static files into your binary. You can use gofiles for this.

Am I missing something when deploying using bitbucket repo and composer deployer?

I am trying to deploy my WordPress site from local to staging. I'm able to deploy the files up to my hosting site but now I'm getting an error in Chrome when I'm trying to access my site http://staging.responsivhub.com/
After uploading my site to my webserver "siteground" in public_html/staging and have changed my subdomains root location to public_html/staging/current/web. After that I'm getting this error
Warning:
require_once(/home/user/public_html/staging/releases/1/vendor/autoload.php):
failed to open stream: No such file or directory in
/home/user/public_html/staging/releases/1/web/wp-config.php on line 7
Fatal error: require_once(): Failed opening required
'/home/user/public_html/staging/releases/1/vendor/autoload.php'
(include_path='.:/usr/local/php71/pear') in
/home/user/public_html/staging/releases/1/web/wp-config.php on line 7
(I have replaced my username to user)
I can't figure out what I'm missing.
You need to create the web/wp-config.php files inside the shared folder with the database credentials and all the WordPress configuration.
Go to (with the webserver/deploy user):
mkdir /home/user/public_html/staging/shared/web
vim /home/user/public_html/staging/shared/web/wp-config.php
And then include the configuration inside that file. After that try to re-run the deploy. I'm not sure if the wp-config.php file is on the root folder so you can try to remove web/ folder when running the commands.

Dockerfile - add file from a windows directory in the .NET Core Web API

I have a .NET Core Web API with a Dockerfile and I want in the Dockerfile, from my Windows host container current user directory to copy a file to the docker container.
Basically, I've tried the following command:
FROM microsoft/aspnetcore:1.1
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ADD C:/Users/MyUser/custom_directory/myfile /root/other_directory/myfile
ENTRYPOINT ["dotnet", "MyApi.dll"]
But I get the following error:
Service 'myservice' failed to build: lstat C:/Users/MyUser/custom_directory/myfile: no such file or directory
How can I fix this error?
You can ADD (copy) only files from a source directory. In this case Visual Studio project directory.
Copy myfile to project directory and add a new line "myfile" to .dockerignore file. Default VS dockerignore file is configured to ignore all files except obj/Docker/publish/* and obj/Docker/empty/.
For better understanding read this:
https://docs.docker.com/engine/reference/builder/#dockerignore-file
https://docs.docker.com/engine/reference/builder/#add

Resources