Using dockerfile ADD and COPY commands on Mac OS X - macos

Is it possible to use the ADD and COPY commands in a Dockerfile on Mac OS X using boot2docker? If so, how? The naive just gives No such file or directory.
So, I've tried two things:
having the file in my local directory (same directory as the Dockerfile) on my Mac.
scping the file into a specific path on the boot2docker-vm and using ADD from that path.
Neither work.
Edit:
Plain vanilla Boot2Docker Mac OS X version 1.2 clean install.
Dockerfile:
FROM centos
ADD ./some.rpm /tmp/some.rpm
RUN rpm -Uvh /tmp/some.rpm
I've tried having some.rpm in the same directory as the Dockerfile, I've tried having it in /home/docker in the boot2docker-vm image, I've tried changing ./some.rpm to /home/docker/some.rpm, etc.

For using "ADD" in a dockerfile you need two things:
First: a directory with your structure
for example:
./my_docker_dir/some.rpm
Second: a valid Dockerfile in my_docker_dir (it has to be named 'Dockerfile')
Your line: 'ADD ./some.rpm /tmp/some.rpm' will work
With that prepared you can build your container with 'docker build -t whatever/youwant .'
For more Information read https://docker.readthedocs.org/en/v0.6.3/commandline/command/build/

I believe you should omit the ./, so if some.rpm is in the same folder as your Dockerfile, try
ADD some.rpm /tmp/some.rpm
If the file is in a sub-folder called files next to your Dockerfile, you can do
ADD files/some.rpm /tmp/some.rpm

I made a simple test case for which it works.
Here is the version info for my setup:
$ boot2docker version
Boot2Docker-cli version: v1.4.1
Git commit: 43241cb
$ docker version
Client version: 1.4.1
Client API version: 1.16
Go version (client): go1.4
Git commit (client): 5bc2ff8
OS/Arch (client): darwin/amd64
Server version: 1.4.1
Server API version: 1.16
Go version (server): go1.3.3
Git commit (server): 5bc2ff8
Here is the test case that you can copy-pasta into your terminal:
date > foo.txt
cat > Dockerfile <<EOF
from centos
ADD foo.txt /datefile.txt
EOF
docker build -t addtest .
docker run -i -t addtest /bin/cat /datefile.txt
It even works if you use the /tmp directory, though I suggest against it since that is supposed to be wiped out on every boot.

Related

Getting : no matching manifest for windows/amd64 10.0.18362 in the manifest list entries

I am just getting started with the docker.
I installed the windows version of the docker and followed some basic steps as given in https://hub.docker.com/?overlay=onboarding.
Unable to build the docker file.
I just cloned a git repo from that
by :
git clone https://github.com/docker/doodle.git
then try to build the docker
cd doodle\cheers2019 ;
docker build -t myrepo/cheers2019 .
I am getting the response on the command line:
Sending build context to Docker daemon 13.31kB
Step 1/9 : FROM golang:1.11-alpine AS builder
1.11-alpine: Pulling from library/golang
no matching manifest for windows/amd64 10.0.18362 in the manifest list entries
DokerFile has
FROM golang:1.11-alpine AS builder
RUN apk add --no-cache git
RUN go get github.com/pdevine/go-asciisprite
WORKDIR /project
COPY cheers.go .
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o cheers cheers.go
FROM scratch
COPY --from=builder /project/cheers /cheers
ENTRYPOINT ["/cheers"]
My PC specs:
Windows 10 - AMD Ryzen5 Processor
Is there is an issue with the AMD processor? Please suggest me some way to solve this.
This is followed by docker/doodle issue 9, and it includes a workaround.
But also the simpler advice:
An alternative is to go to Docker Desktop and select Switch to Linux Containers.
The problem is due to the -alpine part of the tag which unfortunately there is no alpine Linux container which will run on Windows.

Docker: mounting a volume overwrites container

I'm trying to write a Dockerfile for use as a standardized development environment.
Dockerfile:
FROM node:9.5.0
WORKDIR /home/project
# install some stuff...
# clone the repo
RUN git clone https://github.com/... .
# expose
VOLUME /home/project
# fetch latest changes from git, install them and fire up a shell.
CMD git pull && npm install && /bin/bash
After building the image (say with tag dev),
Running docker run -it dev gives me a shell with the project installed and up-to-date.
Of course changes I make in the container are ephemeral so I want to mount /home/project on the host OS, I go to an empty directory project on the host and run:
docker run -it -v ${pwd}:/home/project dev
But my project folder gets overwritten and is empty inside the container.
How can mount the volume such that the container writes to the host folder and not the opposite?
OS: Windows 10 Pro.
When you mount a volume, read/write are both bi-directional by default. That means that anything you write in the container will show up in the host directory and vice versa.
But something weird is happening in your case, right?
In your build process, you are cloning a git repository. During the build process, the volume does not get mounted. The git data resides in your docker image.
Now, when you are running the docker container, you are mounting the volume. The mount path in your container will be synced with your source path. That means the container directory will be overwritten with the contents of the host directory. That's why your git data has been lost.
Possible Solution:
Run a script as CMD. That script can clone the git repo, among other things.
run.sh
#!/bin/bash
# clone the repo
RUN git clone https://github.com/... .
Dockerfile
RUN ADD run.sh /bin
# run run.sh, install them and fire up a shell.
CMD run.sh && npm install && /bin/bash

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 .

Docker unable to process Dockerfile

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 .

Updating boot2docker to 1.4.0 not taking

I'm trying to update docker/boot2docker using boot2docker download command but upon starting it, it is still running 1.3.2 client (docker --version)
bash-3.2$ boot2docker download
Latest release for boot2docker/boot2docker is v1.4.0
Downloading boot2docker ISO image...
Success: downloaded https://github.com/boot2docker/boot2docker/releases/download/v1.4.0/boot2docker.iso
Also, from the docker github OS X installer page, 1.3.2 is the only download option.
Thanks!
You can manually download latest Docker binary and replace the existing one. Instruction here.
This is my shell script to install+update latest Docker on a CentOS6/RHEL:
#!/bin/bash
# YUM install docker with required dependencies
yum -y install docker-io
# Move to a temp working directory
work_dir=$(mktemp -d)
cd "${work_dir}"
trap "rm -rf -- ${work_dir}" EXIT
# WGET latest release of Docker
wget https://get.docker.com/builds/Linux/x86_64/docker-latest -O docker
chmod +x docker
# Replaces Docker with latest Docker binary
mv docker /usr/bin/docker
# Start Docker service
service docker start
Depend on where your binaries are stored, it might be a different location than /usr/bin

Resources