Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is for parser directive in docker

Tags:

docker

I read this link which explains the valid directives. And it says "Parser directive is a special form of comment"

I really don't understand what is the need for this and if it is comment, why docker parses it?

I didn't find any good explanations related to this.

Is it only escape directive? Because of windows path issues.

like image 748
Gibbs Avatar asked Jun 09 '17 08:06

Gibbs


People also ask

How do Dockerfiles work?

Docker can build images automatically by reading the instructions from a Dockerfile . A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. This page describes the commands you can use in a Dockerfile .

What is Run command in Dockerfile?

RUN is an image build step, the state of the container after a RUN command will be committed to the container image. A Dockerfile can have many RUN steps that layer on top of one another to build the image. CMD is the command the container executes by default when you launch the built image.

What does from in Dockerfile mean?

FROM, PULL, RUN, and CMD. FROM - Creates a layer from the ubuntu:18.04. PULL - Adds files from your Docker repository. RUN - Builds your container. CMD - Specifies what command to run within the container.


3 Answers

The "parser directives" instruct the Dockerfile parser to handle the content of Dockerfile as specified in the directives.

"Parser directives" direct the "way" how the content of DockerFile should be treated/interpreted. For this reason, its must be at the top of a Dockerfile.

Currently, "escape" is the only supported directive.

This can be useful for you: https://www.safaribooksonline.com/library/view/learning-docker-/9781786462923/b203797f-2c5f-4f24-a189-9e1780adfbbb.xhtml

like image 117
Alcastic Avatar answered Nov 01 '22 11:11

Alcastic


It basically tell the docker daemon how to read the dockerfile, the way it intended to. For an example, I'll use the escape parser as it's the only supported one right now.

COPY sample.txt c:\\

This will fail as the second '\' at the end of the line interpreted as an escape for the newline, instead of a target of the escape from the first '\'

#escape=`

By adding an escape parser, we can tackle this. However, you have to be careful when using parsers as it's very easy to get them invalidated. You can see the common mistakes stated in Docker docs

like image 33
SAUJ Avatar answered Nov 01 '22 11:11

SAUJ


Parser directive affect the way in which subsequent lines in a Dockerfile are handled / executed. Parser directive must be added at the top of Dockerfile.

For example, \ (backslash) is path separator in windows, whereas in Docker file it is used as escape character. So if we want to change the escape character in Docker files then we can use parser directive

# escape=`

FROM microsoft/nanoserver
COPY testfile.txt c:\
RUN dir c:\

In the above example backtick will be act as escape character instead of backslash.

like image 1
solvease Avatar answered Nov 01 '22 12:11

solvease