Dockerfile copy reference not working in Windows - docker

I've got a Dockerfile that I'm using across Mac, Linux, and Windows. It works fine for Mac & Linux, but Windows 10 is throwing errors.
The Dockerfile:
FROM nginx:1.23.3
WORKDIR /
COPY /nginx-setup.sh /docker-entrypoint.d
RUN chmod +x /docker-entrypoint.d/nginx-setup.sh
The file structure:
- project_root
- docker-compose.yml
- nginx
- Dockerfile
- nginx-setup.sh
When I run docker compose up -d on Mac/Linux, everything works fine. When I run it on Windows, I get the error:
/docker-entrypoint.sh: 31: /docker-entrypoint.d/nginx-setup.sh: not found
I've tried:
COPY /nginx-setup.sh /docker-entrypoint.d
COPY nginx-setup.sh /docker-entrypoint.d
COPY /nginx-setup.sh /docker-entrypoint.d/nginx-setup.sh
The containers spin up, the other services work fine, but the Nginx one throws this error when looking for the setup script. I can't figure out what I'm missing.
All suggestions welcome. Thanks in advance!

Related

Docker - dotnet build can't find file

I am trying to make my application work in a Linux container. It will eventually be deployed to Azure Container Instances. I have absolutely no experience with containers what so ever and I am getting lost in the documentation and examples.
I believe the first thing I need to do is create a Docker image for my project. I have installed Docker Desktop.
My project has this structure:
MyProject
MyProject.Core
MyProject.Api
MyProject.sln
Dockerfile
The contents of my Dockerfile is as follows.
#Use Ubuntu Linux as base
FROM ubuntu:22.10
#Install dotnet6
RUN apt-get update && apt-get install -y dotnet6
#Install LibreOffice
RUN apt-get -y install default-jre-headless libreoffice
#Copy the source code
WORKDIR /MyProject
COPY . ./
#Compile the application
RUN dotnet publish -c Release -o /compiled
#ENV PORT 80
#Expose port 80
EXPOSE 80
ENTRYPOINT ["dotnet", "/compiled/MyProject.Api.dll"]
#ToDo: Split build and deployment
Now when I try to build the image using command prompt I am using the following command
docker build - < Dockerfile
This all processed okay up until the dotnet publish command where it errors saying
Specify a project or solution file
Now I have verified that this command works fine when run outside of the docker file. I suspect something is wrong with the copy? Again I have tried variations of paths for the WORKDIR, but I just can't figure out what is wrong.
Any advice is greatly appreciated.
Thank you SiHa in the comments for providing a solution.
I made the following change to my docker file.
WORKDIR app
Then I use the following command to build.
docker build -t ImageName -f FileName .
The image now creates successfully. I am able to run this in a container.

Quarkus native executable built on Windows not running inside a Docker container

First, I build a Quarkus native image, everything seems to be fine. When I try to run it, I get the following error:
standard_init_linux.go:228: exec user process caused: no such file or directory
This is the Dockerfile:
FROM alpine:3.15
WORKDIR /deployment/
COPY native/*-runner /deployment/app
RUN chmod 775 /deployment
EXPOSE 8082
USER 1001
ENTRYPOINT [ "./app","-Dquarkus.http.host=0.0.0.0"]
I'm on a Windows machine and the command used to generate the native executable (the *-runner file) is:
mvn package -Pnative -Dquarkus.package.type=native -Dquarkus.native.container-build=true
I'm not sure what I'm doing wrong, after browsing similar issues, some were solved with the -Dquarkus.native.container-build=true flag, but it didn't work in my case. Thank you !
The problem was in the Dockerfile, I was using alpine:3.15 as base image.
After reading the guide again, this fixed the problem:
FROM quay.io/quarkus/quarkus-micro-image:1.0

Error while creating mount source path when using docker-compose in Windows

I am trying to dockerize my React-Flask app by dockerizing each one of them and using docker-compose to put them together.
Here the Dockerfiles for each app look like:
React - Frontend
FROM node:latest
WORKDIR /frontend/
ENV PATH /frontend/node_modules/.bin:$PATH
COPY package.json /frontend/package.json
COPY . /frontend/
RUN npm install --silent
RUN npm install react-scripts#3.0.1 -g --silent
CMD ["npm", "run", "start"]
Flask - Backend
#Using ubuntu as our base
FROM ubuntu:latest
#Install commands in ubuntu, including pymongo for DB handling
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
RUN python -m pip install pymongo[srv]
#Unsure of COPY command's purpose, but WORKDIR points to /backend
COPY . /backend
WORKDIR /backend/
RUN pip install -r requirements.txt
#Run order for starting up the backend
ENTRYPOINT ["python"]
CMD ["app.py"]
Each of them works fine when I just use docker build and docker up. I've checked that they work fine when they are built and ran independently. However, when I docker-compose up the docker-compose.yml which looks like
# Docker Compose
version: '3.7'
services:
frontend:
container_name: frontend
build:
context: frontend
dockerfile: Dockerfile
ports:
- "3000:3000"
volumes:
- '.:/frontend'
- '/frontend/node_modules'
backend:
build: ./backend
ports:
- "5000:5000"
volumes:
- .:/code
Gives me the error below
Starting frontend ... error
Starting dashboard_backend_1 ...
ERROR: for frontend Cannot start service sit-frontend: error while creating mount source path '/host_mnt/c/Users/myid/DeskStarting dashboard_backend_1 ... error
ERROR: for dashboard_backend_1 Cannot start service backend: error while creating mount source path '/host_mnt/c/Users/myid/Desktop/dashboard': mkdir /host_mnt/c: file exists
ERROR: for frontend Cannot start service frontend: error while creating mount source path '/host_mnt/c/Users/myid/Desktop/dashboard': mkdir /host_mnt/c: file exists
ERROR: for backend Cannot start service backend: error while creating mount source path '/host_mnt/c/Users/myid/Desktop/dashboard': mkdir /host_mnt/c: file exists
ERROR: Encountered errors while bringing up the project.
Did this happen because I am using Windows? What can be the issue? Thanks in advance.
For me the only thing that worked was restarting the Docker deamon
Check if this is related to docker/for-win issue 1560
I had the same issue. I was able to resolve it by running:
docker volume rm -f [name of docker volume with error]
Then restarting docker, and running:
docker-compose up -d --build
I tried these same steps without restarting my docker, but restarting my computer and that didn't resolve the issue.
What resolved the issue for me was removing the volume with the error, restarting my docker, then doing a build again.
Other cause:
On Windows this may be due to a user password change. Uncheck the box to stop sharing the drive and then allow Docker to detect that you are trying to mount the drive and share it.
Also mentioned:
I just ran docker-compose down and then docker-compose up. Worked for me.
I have tried with docker container prune then press y to remove all stopped containers. This issue has gone.
I saw this after I deleted a folder I'd shared with docker and recreated one with the same name. I think this deleted the permissions. To resolve it I:
Unshared the folder in docker settings
Restarted docker
Ran docker container prune
Ran docker-compose build
Ran docker-compose up.
Restarting the docker daemon will work.

Docker for Windows exits with code 127 when building image

When I try to build this Docker-Image, I get the following error:
FROM java:8
WORKDIR /app
ADD . /app
EXPOSE 8080
RUN ./gradlew build
CMD ./gradlew bootRun
When I just build the app with "gradlew build" it runs and when I try to run this Docker Image with a Mac, it works too, just not for windows
EDIT:
This is not a great answer, but what I found is that when Windows mounts files into Docker from Windows, it leaves Windows-like line endings on the mounted files. A janky way to solve it in your Dockerfile would be to install dos2unix in the container and add a
RUN dos2unix gradlew
prior to executing your build process. Unfortunately, this is a TERRIBLE solution. Hopefully Docker for Windows on WSL2 that is supposed to release soon will solve this better but for now you are stuck with this janky solution.
gradlew must be marked as executable.
chmod +x gradlew
Mac and Linux share permissions scheme but Windows needs to use a virtual FS so it copies files with default permissions - 644 and you need 755.

Error response from daemon: Dockerfile parse error line 1: unknown instruction: #

Im new to docker and trying to learn it.
Im following this tutorial: https://docs.docker.com/get-started/part2/#apppy
So I installed Docker on Windows.
Created 3 files, app.py, Dockefile and requirements.txt
My docker file looks like this
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
CMD ["python", "app.py"]
When I run it in powershell
docker build -t friendlybuild .
But as result it gives this:
Error response from daemon: Dockerfile parse error line 1: unknown instruction: #
Like it doesnt work
I have no idea why it doesnt work
I forgot to have a whitespace in ENTRYPOINT["java",
It should be ENTRYPOINT ["java",
I just tested the same and by default VSCode seems to save the Dockerfile with UTF-16 LE encoding.
Resaving the file as UTF-8 allowed docker build to run without error.
Solved by removing the dockerfile and creating it with Notepad instead of Visual Code
I had an extra line break in my Dockerfile. Didn't even notice it until I read some of these comments and realized it could be a problem. Originally my file was:
FROM openjdk:8
COPY . /usr/src/Main
WORKDIR /usr/src/Main
ENTRYPOINT ["java", "-Xmx700m","-classpath", ".:./resources/:./lib/*",
"org.spark.docker.demo.DockerMultilayerPerceptronClassifier"]
and the error I was seeing was:
$ docker build -t docker-classifier .
Sending build context to Docker daemon 248.3MB
Error response from daemon: Dockerfile parse error line 5: unknown instruction: "ORG.SPARK.DOCKER.DEMO.DOCKERMULTILAYERPERCEPTRONCLASSIFIER"]
Took me a while to figure it out until I read some of these comments above and looked into the line formatting and realized "org.spark.docker.demo.DockerMultilayerPerceptronClassifier"] was on a line of it's own. Once I removed the line break before it everything worked fine. I assumed the parser would ignore it.
When doing it from Windows, I had to make sure that I have line breaks in my Dockerfile configured for Linux (LF) and not for Windows (CRLF) when editing it from a text editor.
In Google Cloud Platform in console project using nano the comand work for me
1ยบ-nano
2-
# The Dockerfile defines the image's environment
# Import Python runtime and set up working directory
FROM python:2.7-alpine
WORKDIR /app
ADD . /app
# Install any necessary dependencies
RUN pip install -r requirements.txt
# Open port 80 for serving the webpage
EXPOSE 80
# Run app.py when the container launches
CMD ["python", "app.py"]
save the file...
I experienced this issue when working on a React app setup on Docker.
Sending build context to Docker daemon 1.143MB
Error response from daemon: Dockerfile parse error line 1: unknown instruction: +#
Here's how I solved it
The issue was that I had another file named Dockerfile (capital case D) which had some instructions in it, and it was conflicting with the original dockerfile (lower case d) in my project root directory.
I fixed this by deleting the Dockerfile and running the command:
docker build t myapp:latest .
to build the docker image from the dockerfile instead.
That's all.
I hope this helps
While running, appended some text in the start of the file. Removed those using vi in terminal and working fine.
i run docker compose in intellij idea, solved this by remove the number in docker parent folder name.
For mac users who face this issue:
Just edit/create Dockerfile using Python IDLE and remove extension.

Resources