Matt C.
Matt C.

Reputation: 3320

How do you print to console from a docker file during build?

Suppose you have some Dockerfile. What needs to be added to that file such that a string (ie "Hello World") is printed to the console during build?

docker build .

Upvotes: 77

Views: 116803

Answers (3)

Carl Yamamoto-Furst
Carl Yamamoto-Furst

Reputation: 1

This might not be what you want, but if you have Docker desktop you can select the Builds tab, search for the image name:tag you created and select the logs tab. All the output from all steps should be there.

Upvotes: 0

alar
alar

Reputation: 53

I like to keep notes to remind myself what I am doing and display logs to myself to verify that it happens in this version. RUN it is

# Copy local config into container
COPY config/kibana.yml /opt/kibana/config/kibana.yml

# Verify that local configuration file is copied in & enables SSL/TLS
RUN ls -l /opt/kibana/config/

Upvotes: -1

Noam Yizraeli
Noam Yizraeli

Reputation: 5454

It's fairly simple actually. If you just want to print stuff using in the build proccess you could just add the following line to your Dockerfile:

RUN echo "hello there"

And then add these options to your docker build command:

--progress=plain --no-cache

EDIT:

as noted by @SoftwareEngineer, when used for logging or tooling purposes you should append the echo command to the one you want to check if were successful. for example when downloading packages and wanting to get a print statement when finished: example from nginx official image dockerfile

RUN apt-get install -y whatever && echo "installed package"

Upvotes: 119

Related Questions