I have a dockerfile that copies entire directory to the image and a single file is not copied. The file is located in a subfolder with 2 other files which do get copied.
there is no .dockerignore.
It is a sqlite db file.
this is the dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:6.0
COPY . App/
WORKDIR /App
RUN sed -i 's/TLSv1.2/TLSv1.0/g' /etc/ssl/openssl.cnf
RUN ["chmod", "+x", "/App/entrypoint/entry_script.sh"]
ENTRYPOINT ["/App/entrypoint/entry_script.sh"]
Check if there is this file .dockerignore
This file tells the docker to exclude specific files or folders to be copied to docker image.
Related
Being new to docker files. I am trying to understand how docker build is working here.
I currently have a folder that has two files in it. The folder is called foo
The structure of the folder is as follows. It has two files in it the first file is main.go and the other file next to it is Dockerfile as shown in the diagram below
Foo
|_main.go
|_go.mod
|_go.sum
|_Dockerfile
My Dockerfile currently looks like this and the command docker build -t .. is called from inside the folder Foo.
FROM golang:1.18-alpine AS builder
# Create and change to the app directory.
WORKDIR /app
COPY go.* ./
RUN go mod download
# Copy local code to the container image.
COPY . ./
RUN go build -v -o my app
....
Now this is a fairly simple Dockerfile. Here is what I understand.
1- golang:1.18-alpine is the base image
2- In the container a folder called app will be created
3- go.mod and go.sum will be copied to ./ path of the container (probably home) of the container.
4- Run go mod download will be called from inside the /app folder correct ?
My question is basically for no. 4. go mod download called from inside /app folder ? If so how does that work because from my understanding is that the /app folder is so far empty ? When did the app folder get populated ? In the statement COPY go.* ./ what path is ./ is that the home ?
In line WORKDIR /app, your current path will be set to /app. If the directory don't exist then it will be created beforehand.
Next COPY go.* ./, this matches all of files start with go. will be copied to /app directory in the docker container. So your docker /app should look like this :
/app
| go.mod
| go.sum
Again with COPY . ./, you are copying all files from current directory to /app directory of your docker container. It will replace already existing files in the contrainer. /app will look like this:
/app
| main.go
| go.mod
| go.sum
| Dockerfile
Last with RUN go build -v -o myapp, you are building the app using go and saving binary file myapp.
I have a Dockerfile and I want to add/copy a file.txt from my Desktop. How can I do?
This is my docker file:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build-env
WORKDIR /app
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim
WORKDIR /app
COPY --from=build-env /app/out ./
# COPY ...
RUN useradd -ms /bin/bash moduleuser
USER moduleuser
ENTRYPOINT ["dotnet", "csharpexamplemodule.dll"]```
Short answer: You don't (see Adding files from outside context).
As far as copying (COPY / ADD) goes the file you want to copy to the container needs to be in the same context. Context in this case is the directory of your dockerfile or one of it's subdirectories. Assuming your dockerfile is not on the desktop as well, you are left with 2 options.
Copy the file from your desktop to the context that docker gets, as mentioned above
If you don't need the file during the build stage but still within your container, you can use docker mount (docker mount docs).
if you check the docker documentation of the copy command, you should see the following:
https://docs.docker.com/engine/reference/builder/#copy
COPY obeys the following rules:
The <src> path must be inside the context of the build;
you cannot COPY ../something /something, because the first
step of a docker build is to send the context directory
(and subdirectories) to the docker daemon.
So I would suggest you copy the file from your desktop to your docker context (where you run the docker command from). Or to create a symbolic link.
PS: It is a good practice to avoid using ADD if you don't need the tar and remote URL handling.
I have the docker file as follows:
FROM node:8 as builder
WORKDIR /usr/src/app
COPY ./src/register_form/package*.json .
RUN npm install
COPY ./src/register_form .
RUN yarn build
FROM tensorflow/tensorflow:1.10.0-gpu-py3
COPY --from=builder /usr/src/app/register_form/build/index.html /app/src/
WORKDIR /app
ENTRYPOINT ["python3"]
CMD ["/app/src/main.pyc"]
However, it cannot copy the index.html from the builder stage. Although when I list the folder in the first stage, the files are there.
The error is:
Step 8/22 : COPY --from=builder ./register_form/build/ /app/src/
COPY failed: stat /var/lib/docker/overlay2/5470e05501898502b3aa437639f975ca3e4bfb5a1e897281e62e07ab89866304/merged/register_form/build: no such file or directory
How can I fix this problem - the COPY --from=builder docker command?
I think you are misusing COPY command. As it is told in docs:
If src is a directory, the entire contents of the directory are
copied, including filesystem metadata.
Note: The directory itself is not copied, just its contents.
So your command COPY ./src/register_form . does NOT create register_form folder in container, but instead copies all contents. You can try adding:
RUN ls .
to your Dockerfile to make sure.
As noticed by #BMitch in comments, you can explicitly set destination folder name to achieve expected results:
COPY ./src/register_form/ register_form/
I have a source code and I want to add it into docker image using Dockerfile. I use COPY command, but I don't know what I should put in destination place. Can you tell me if destination is a specific directory or it is optional?
The destination directory can be a directory of your choice.
...
RUN mkdir -p /usr/src/app
COPY ./src /usr/src/app
...
The above commands in a Dockerfile would create /usr/src/app in the containers filesystem and the COPY would copy the contents of the src directory on the host to /usr/src/app in the containers filesystem.
You can use any destination path , but make sure that path exist for example
COPY source_code / opt/folder_name
Then optionally you can make this in docker as working directory
WORKDIR /opt/folder_name
in Dockerfile:
COPY ./src /dst
Where src is a folder in the same path of Dockerfile on the host (the computer on which Docker is directly running). dst is a folder on the container itself.
Here is an example:
Create a Dockerfile for an ASP.NET Core application
# Copy everything
COPY . /FolderInTheContainer/
this will copy everything in the same path of Dockerfile, to a destination folder in the container.
Here is dockerfile copy documentation:
https://docs.docker.com/engine/reference/builder/#copy
The Docker image (Windows-based) includes an application directory at C:\App. Inside that directory reside several sub-folders and files, including a batch file called process.bat. The Dockerfile (used to build the image) ends like this:
ENTRYPOINT [ "C:\\App\\process.bat" ]
When I instantiate this image using the command: docker run company/app, the batch file runs, but it fails at the point where other files under C:\App are referenced. Essentially, the working directory is still C:\ from the Docker container's entry-point.
Is there a way to set the working directory within the Dockerfile? Couple of alternatives do exist:
Add -w C:\App to the docker run
In the batch file, I can add a line at the beginning cd /D C:\App
But is there a way to specify the working directory in the Dockerfile?
WORKDIR /App is a command you can use in your dockerfile to change the working directory.
If /App is a mounted volume then you should specify VOLUME /App before WORKDIR to use it with ENTRYPOINT, otherwise it does not be seen by ENTRYPOINT:
VOLUME ["/App"]
WORKDIR /App
ENTRYPOINT ["sh", "start.sh"]
Which start.sh is within /App directory.