Z
Z
zlodiak2019-06-17 11:54:59
Docker
zlodiak, 2019-06-17 11:54:59

How to write text to a file?

I'm trying to create my own image based on the ubuntu:latest image, in which the /helloworld file will exist with the name of the current system user. Here is the Dockerfile:

FROM ubuntu
COPY helloworld /helloworld
RUN echo $USER > /helloworld

After creating the image, I run it as a container (I hope I'm not confusing anything in terminology) in interactive mode:
docker run -t -i docktor888/hw /bin/bash
and I plan to see the username: in this file
ls && cat /helloworld
, but this file is empty.
Please help me fix the Dockerfile so that /helloworld contains the name of the current user.
PS:
Of course, before starting the build, I manually create
touch /helloworld

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Georg Gaal, 2020-02-02
@gecube

Most likely, the $USER variable is simply not defined at the build stage.
Even worse, you can redefine the user when starting the container from the image, and such a docker image will become meaningless:

docker run -u <айди пользователя> <имя образа> whoami

decision? Write docker-entrypoint.sh (specify it as entrypoint), which will create this file during container startup.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question