Docker's heredoc example for RUN is not working - docker

I tried to implement the example provided by Docker itself (https://www.docker.com/blog/introduction-to-heredocs-in-dockerfiles/)
# syntax=docker/dockerfile:1.3-labs
FROM ubuntu:20.04
RUN <<EOF
echo "Hello" >> /hello
echo "World!" >> /hello
EOF
using docker version
~/test$ docker --version
Docker version 20.10.22, build 3a2c30b
but it throws the error
~/test$ docker build .
Sending build context to Docker daemon 2.048kB
Error response from daemon: dockerfile parse error line 6: unknown instruction: ECHO
I've also tried it with dockerfile versions 1, 1.3, 1.4, 2, 2.0. Nothing worked. Am I doing something wrong or is it just not working (yet)?

You need to use the buildkit toolkit for that:
$ DOCKER_BUILDKIT=1 docker build .

Related

docker build RUN error while loading shared libraries

I am having trouble making a simple build run on my RHEL server.
When running docker build I get
Step 2/2 : RUN echo "Hello there!"
---> Running in 0d0fd7f69a5f
/bin/sh: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
The command '/bin/sh -c echo "Hello there!"' returned a non-zero code: 127
Dockerfile:
FROM ubuntu:latest
RUN echo "Hello there!"
RHEL 7.7 - Linux 3.10.0-1062.9.1.el7.x86_64
Docker version 1.13.1, build 4ef4b30/1.13.1
The Dockerfile is fine - I can build the image on any other machine so I am wondering where the issue actually is. Thanks!
Thanks to everyone for the suggestions!
Turns out it was an SELinux issue. Seems Docker needs SELinux to be configured properly to run (in my case I chose to disable SELinux using sudo setenforce 0).

"docker run --rm hello" run into "failed: No such file or directory" error

I am new to docker, and follows the instructions at https://docs.docker.com/develop/develop-images/baseimages/ to create a docker image and tried to run:
My docker file is as follows:
FROM scratch
ADD hello.sh /
CMD ["/hello.sh"]
The hello.sh file is as follows. I have applied dos2unix to hello.sh to ensure the right encoding:
#!/bin/sh
echo "this is a test"
I followed the instruction in the doc to run the following command to build an image:
docker build --tag hello .
Then when I ran docker run --rm hello I got the following error:
[FATAL tini (8)] exec /hello.sh failed: No such file or directory
Have searched online and tried solutions from various posts. But none of them worked. Any insights on where I did wrong?
related non-helpful threads:
1. https://forums.docker.com/t/standard-init-linux-go-175-exec-user-process-caused-no-such-file/20025/4
Building an image from 'scratch' means your resulting container is just an empty filesystem. Especially being new to Docker, you should build from a small image like 'alpine' instead of 'scratch' then run your script using sh.
If you are set on building from scratch you will need to compile your own binary then add it as the ENTRYPOINT or CMD of the image Install Bash on scratch Docker image
docker documentation example on building from scratch https://docs.docker.com/develop/develop-images/baseimages/

Can't build Dockerfile

I’m running docker [Docker 18.06.1-ce, build e68fc7a] on an Ubuntu 18 machine.
Simply carrying out a very simple exercise from docker in order to build a dockerfile : https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
On running the following command
docker build -t helloapp .
I get the following error
error checking context: 'can't stat '/home/aielloine/.docker/helloapp/dockerfiles''.
The docker file:
FROM busybox
COPY /hello
RUN cat /hello
You are missing the source, i.e. the file you want to copy inside the iamge, in your COPY command:
FROM busybox
COPY <source> /hello
# ^
# |
# This is missing
RUN cat /hello

Why is the docker image not building?

I was following the tutorial on the official website.
https://docs.docker.com/get-started/part2/#build-the-app
I created a directory named dir and added the Dockerfile, app.py and requirements.txt. When I try to build this, the error is-
root#ubuntu:~/dir# docker build -t hello
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | - [flags]
Build an image from a Dockerfile
You forgot to mention location of context-root
#>docker build -t hello .
Add a . at the end if Dockerfile is at the current location

docker build is not work

I can't seem to get docker build to run correctly:
wangyaos-MBP-3:~ wangyao$ cd /Users/wangyao/Ozintel/docker/flexcloud/
wangyaos-MBP-3:flexcloud wangyao$ ls
Dockerfile apache-tomcat-7.0.62 jdk1.8.0_45.jdk
wangyaos--3:flexcloud wangyao$ docker build -t="Users/wangyao/Ozintel/docker/flexcloud" .
Invalid namespace name (Users). Only [a-z0-9-_] are allowed.
wangyaos-MBP-3:flexcloud wangyao$ cd /Users/wangyao/
wangyaos-MBP-3:~ wangyao$ docker build -t="Users/wangyao/Ozintel/docker/flexcloud" .
Cannot locate Dockerfile: Dockerfile
wangyaos-MBP-3:~ wangyao$ docker build -t="Users/wangyao/Ozintel/docker/flexcloud"
docker: "build" requires 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build a new image from the source code at PATH
How should I use docker build?
Slow down and take a look at the docs.
To use docker build, the easiest way is to cd into the directory with the Dockerfile then run something like:
$ docker build -t flexcloud .
The -t argument specifies the repository name and tag, not the directory with the Dockerfile. If you want to give a path to a different Dockerfile, you can use the -f argument. The . at the end specifies the "build context", in this case the current working directory.

Resources