Docker unable to process Dockerfile - windows

I trying to create Dockerfile file from scratch on Windows7. However, currently have trouble on very first step. My Dockerfile is placed under C:\Users\Arturas\Docker\Jenkins. Virtual Box shared folder path on c:\Users and folder name on c/Users (defaults from boot2docker was not changed).
When I run (on git bash):
$ docker build --file Docker/Jenkins/ .
I get:
unable to process Dockerfile: read C:\Users\Arturas\Docker\Jenkins:
The handle is invalid.
Dockerfile content is just one line:
FROM jenkins
I just started learning Docker so my experience is very limited yet. However from tools like boot2docker I expect basic commands to work out of the box so I must be missing something.

Try instead:
cd /C/Users/Arturas/Docker/Jenkins
docker build -t myimage .
I assume here that you have a file named Dockerfile under the Jenkins folder.
The -f option of a docker build is for referencing the Dockerfile (if it is named differently for instance)
Don't forget to use the latest docker-machine (the 0.5.4 one: an auto-extractible exe docker-machine_windows-amd64.exe): it uses a VM named boot2docker.iso through VirtualBox.

Try to specify the "Dockerfile" name
$ docker build --file Docker/Jenkins/Dockerfile .

Related

Docker compose V2: unknown shorthand flag 'f' (windows)

I'm currently running docker desktop version 20.10.22 (build 3a2c30b, fresh install) on Windows (using wsl2), but docker compose commands with the -f flag do not work correctly. Since I'm using docker compose V2 (checked the option in the docker desktop settings), my commands are with a space instead of a hyphen. I get the following message when running any docker compose command using -f:
unknown shorthand flag: 'f' in -f See 'docker --help'.
Specifically, I'm running the FIWARE NGSI-LD tutorials. All docker compose commands that are used within those tutorials fail. The commands can be found in the services file for each tutorial. For example, a command that fails (saying that the -f flag does not exist) within the Short-Term-History tutorial is the following:
docker compose -f docker-compose/mintaka.yml -p fiware up -d --remove-orphans --renew-anon-volumes
The weird thing is that docker compose --help and docker compose --version both return the output from respectively docker --help and docker --version, as if it excludes the compose keyword. The output of the above command also refers to the standard docker help command instead of the docker compose help.
UPDATE: Docker excludes the compose keyword between docker and the rest of the command. Replacing compose with a random string of letters gives the same effect. It seems as if it cannot recognize the compose keyword.
The old docker-compose is not installed so that does not work either. Running which docker-compose returns the docker-compose.exe location, inside the .../Docker/resources/bin folder. Running which docker compose returns the location of docker.exe. The .../Docker/resources/bin folder is inside the path environment variable.
Does anybody know what the problem might be? I've searched countless websites but did not find any solutions for this problem yet.
Kind regards
Here is what I have in running processes when I run docker compose events:
Please check if you have all these directories and files. Then we can troubleshoot further.
I reinstalled docker desktop with the same installer (also same version) and this resolved the problem weirdly enough...
The only difference between my old and new installation was that I already had wsl2 installed this time.

Docker Toolbox: Could not locate Gemfile since Host directory is not mounted to Home directory

I have Docker Toolbox installed on my local machine and I'm trying to run Ruby commands to perform database migrations. I am using the following docker commands within the Docker Toolbox Quickstart Terminal Command Line:
docker-compose run app /usr/local/bin/bundle exec rake db:migrate
docker-compose run app bundle exec rake db:create RAILS_ENV=production
docker-compose run app /usr/local/bin/bundle exec rake db:seed
However, after these commands are called, I get the following error:
Could not locate Gemfile or .bundle/ directory
Within Docker Toolbox, I am within my project's directory as I run these commands (C:\project).
After doing some research, it appears that I need to mount my Host directory somewhere inside my Home directory.
So I tried using the following Docker Mount commands:
docker run --mount /var/www/docker_example/config/containers/app.sh:/usr/local/bin
docker run --mount /var/www/docker_example/config/containers/app.sh:/c/project
Both of these commands are giving me the following error:
invalid argument "/var/www/docker_example/config/containers/app.sh:/usr/local/bin" for --mount: invalid field '/var/www/docker_example/config/containers/app.sh:/usr/local/bin' must be a key=value pair
See 'docker run --help'
Here is what I have in my docker-compose.yml file:
docker-compose.yml:
app:
build: .
command: /var/www/docker_example/config/containers/app.sh
volumes:
- C:\project:/var/www/docker_example
expose:
- "3000"
- "9312"
links:
- db
tty: true
Any help would be greatly appreciated!
The issue is because you are running on windows. You need a shared folder between your Docker machine and the Host machine.
Above is on my mac. You can see my /Users is shared as /Users inside the VM. Which means when I do
docker run -v ~/test:/test ...
It will share /Users/tarun.lalwani/test inside the VM to /test inside the container. Now since /Users inside the VM is shared to my host this would work perfectly. But if I do
docker run -v /test:/test ...
Then even if I have /test on my mac it won't be shared. Because the host mount path is dependent on the Docker host server.
So in your case you should check which folder is shared and then to what path is it shared. Assuming C:\ is shared at /c Then you would use below to get your files inside the VM
docker run -v /c/Project:/var/www/html ..

How can I resolve the error oci runtime error: exec: no such file or directory when using docker run on Windows

When running a Docker command such as
docker run ubuntu /bin/echo 'Hello world'
used in the in the starter example docs on the Learn by Example page of the Docker docs I see the error
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: oci runtime error: exec: "C:/Program Files/Git/usr/bin/bash": stat C:/Program Files/Git/usr/bin/bash: no such file or directory.
How can I resolve this?
This error could be caused by the setup on your system including mingw (you might see this if you have installed Git for Windows with MSYS2 for example - see here for more information). The path is being converted - to stop this you can use a double slash // before the command. In this example you can use
docker run ubuntu //bin/echo 'Hello world'
(notice the double slash (//) above). If all goes well you should now see
Hello world
An complete and slightly more complex example is starting an Ubuntu interactive shell
docker run -it -v /$(pwd)/app:/root/app ubuntu //bin/bash
Note that in my case using Git Bash I only needed one extra slash because echo $(pwd) on my machine expands to:
/c/Users/UserName/path/to/volume/mount
As another example the following can be used if zip is not available (as is the case on Windows 10 as well as Git Bash) You cannot easily zip a file for a something like an AWS Lambda function (actually there are few ways without Docker or even installing third party software if you prefer). If you want to zip the app folder under your current directory use this:
docker run -it -v /$(pwd)/app:/root/app mydockeraccount/dockerimagewithzip //usr/bin/zip -r //root/app/test1.zip //root/app
The mydockeraccount/dockerimageqithzip can be build by creating a Dockerfile like this:
FROM ubuntu
RUN apt-get update && apt-get install -y zip
Then run:
docker build -t mydockeraccount/dockerimagewithzip .

Dockerfile, how to create images ubuntu 14.04

Yesterday I've been asked about how to make a docker images with dockerfile
This time I want to add a question
If I want to make the OS ubuntu 14:04 on images docker, which it is installed, postgresql-9.3.10, install Java JDK 6, copy the file (significant location), and create a user on the images.
Whether I can combine of several dockerfile as needed for images? (dockerfile of postgresql, java, copyfile, and create a user so one dockerfile)
Example. I made one dockerfile "ubuntu"
which contains the command
top line
# Create dockerfile
# get OS ubuntu to images
FROM ubuntu: 14:04
# !!further adding a command on the following link, below the line per-dockerfile(intends command in dockerfile on the link)
# command on dockerfile postgresql-9.3
https://github.com/docker-library/postgres/blob/ed23320582f4ec5b0e5e35c99d98966dacbc6ed8/9.3/Dockerfile
# command on dockerfile java
https://github.com/docker-library/java/blob/master/openjdk-6-jdk/Dockerfile
# create a user on images ubuntu
RUN adduser myuser
# copy file/directory on images ubuntu
COPY /home/myuser/test /home/userimagedockerubuntu/test
# ?
CMD ["ubuntu:14.04"]
Please help me
No, you cannot combine multiple Dockerfile.
The best practice is to:
start from an imabe already included what you need, like this postgresql image already based on ubuntu.
That means that if your Dockerfile starts with:
FROM orchardup/postgresql
You would be building an image which already contains ubuntu and postgresql.
COPY or RUN what you need in your dockerfile, like for openjdk6:
RUN \
apt-get update && \
apt-get install -y openjdk-6-jdk && \
rm -rf /var/lib/apt/lists/*
ENV JAVA_HOME /usr/lib/jvm/java-6-openjdk-amd64
Finally, your default command should run the service you want:
# Set the default command to run when starting the container
CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
But since the Dockerfile of orchardup/postgresql already contains a CMD, you don't even have to specify one: you will inherit from the CMD defined in your base image.
I think nesting multiple Dockerfiles is not possible due to the layer system. You may however outsource tasks into shell scripts and run those in your Dockerfile.
In your Dockerfile please fix the base image:
FROM ubuntu:14.04
Further your CMD is invalid. You may want to execute a bash with CMD ["bash"] that you can work with.
I would suggest you to start with the doc on Dockerfile as you clearly missed this and it contains all the answers to your questions, and even questions you don't even think to ask yet.

ADD Command for Docker Toolbox on Mac

I have Docker Toolbox installed on my Mac, but I'm having issues adding a file to a container during build. I'm using the ADD command in the Dockerfile. I can't seem to add any local files. I understand that Docker Toolbox uses VirtualBox under the hood, but I am not sure how to get those files into the VM to build the container. Is there a way I can do it that allows me to keep a clean OS-agnostic Dockerfile without any absolute paths?
Here is my Dockerfile. It's built from the Node.js container with some additional dependencies.
FROM node:4.2.2
RUN apt-get update
RUN apt-get install -y libvips-dev libgsf-1-dev libkrb5-dev
RUN apt-get clean
ADD app/ /app
RUN cd /app && npm install --production
RUN npm install forever -g
Turns out this does work, but only for my current directory. My Dockerfile and the files I wanted to add were not in the same directory. Moving the shell to the files I wanted, and then manually specifying the Dockerfile worked.
docker build -f my/other/Dockerfile .
Since docker will use a VirtualBox VM on Mac (with boot2docker or with docker-machine), it will use VirtualBox Guest Additions, which is there for the express purpose of using VirtualBox folder sharing.
Make sure to be in such a shared path, typically in /Users/....
If app/ is in /Users/path/to/app, then ADD should work.
You can mount other paths with boot2docker, but it can be problematic with docker machine (see issue 13).
Of course, for ADD app ... to work, you need to be in the parent folder of app/.
From docker ADD:
The <src> path must be inside the context of the build; you cannot ADD ../something /something

Resources