I'm trying to build a dockerimage from docker file, i'm setting an ENV in the Dockerfile(ENV GOROOT "/usr/share/go/1.6").. But I couldn't find the same ENV value inside the container. The value is set as "/usr/share/go". "/1.6" is missing.
Steps to reproduce the issue:
build the Dockerfile https://gist.github.com/anumantharaja/afa1fc1684a58b2646e2ae2d80489686
Run the image
and inside the container give echo $GOROOT
Result i received:
i received /usr/share/go
Result i expected:
i expected /usr/share/go/1.6
Dockerfile
FROM busybox
### Add Env
ENV GOPATH /root/.gopkg/
ENV GOROOT /usr/share/go/1.6
ENV PATH $PATH:$GOROOT/bin
Build the image
docker build -t rom .
Start a container from the image:
docker run -d -it rom /bin/sh
5dea13c392bcf8740d918be61e8d0c22d20835353a020111f467b928a8990e08
Go inside container
docker exec -it 5dea13c392bcf8740d918be61e8d0c22d20835353a020111f467b928a8990e08 /bin/sh
Echo the env var
/ # echo $GOROOT
/usr/share/go/1.6
This is not an answer. Just to show him that it worked in my case.
Maybe it isn't working with his base image.
Related
I'm brand new user of Docker...
I'm tring use Enviroments variables on my Dockerfile...
It's like that:
FROM openjdk:11-jdk-slim-buster
ENV JAVA_APP my-app
EXPOSE 8080
COPY target/$JAVA_APP-*.jar /app/$JAVA_APP.jar
CMD java -jar /app/$JAVA_APP.jar
The result is that: the COPY command gets the value of JAVA_APP variable. But the CMD command doesn't.
Is there some another way to use ENV variables?
If I make this super simple Dockerfile
FROM ubuntu
ENV JAVA_APP my-app
CMD echo $JAVA_APP
and build and run it with
docker build -t test .
docker run --rm test
docker run --rm -e JAVA_APP=Hello test
It prints 'my-app' and 'Hello'. So it does work. If it still doesn't work for you, can you expand your post with the command you use to run the container?
I want to concatenate JSON environment variable out of multiple parameters provided during runtime.
Simplified Dockerfile:
FROM ubuntu:18.04
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS='{"endpointCredentials": [{"endpoint":"'${AZP_ENDPOINT}'", "username":"someuser", "password":"'${AZP_TOKEN}'"}]}'
Then i build image like this:
docker build -t myubuntu .
and run it
docker run -it -e AZP_ENDPOINT="https://pkgs.dev.azure.com/myorg/nuget/v3/index.json" -e AZP_TOKEN="some token" myubuntu
However when i run env command inside the container i see the following picture. Variable provided during container run are there, but VSS_NUGET_EXTERNAL_FEED_ENDPOINTS has not been updated:
AZP_ENDPOINT=https://pkgs.dev.azure.com/myorg/nuget/v3/index.json
AZP_TOKEN=some token
VSS_NUGET_EXTERNAL_FEED_ENDPOINTS={"endpointCredentials": [{"endpoint":"", "username":"someuser", "password":""}]}
Just wondering what i'm doing wrong here?
FROM alpine:3.11
COPY out/ /bin/
CMD ["command", "--flag1", "${HOST}", "--flag2", "${PORT}", "--flag3", "${AUTH_TOKEN}"]
This is the docker file used. I am loading the env variables during run through an env file.
But the variables are not substituted when running the command. If I override the CMD and exec into the container I am able to see the envs though.
What am I missing here?
You are running CMD in exec mode. Switch to shell mode and it will work out. As for the environment variables to be present you need a shell. more reading
your example:
CMD command --flag1 ${HOST} --flag2 ${PORT} --flag3 ${AUTH_TOKEN}
Full generic example:
Dockerfile:
FROM debian:stretch-slim
CMD echo ${env}
Run:
docker build .
docker run --rm -e env=hi <image id from build step>
hi
According to this:
https://hub.docker.com/_/mysql/
I can set the MySQL root password with:
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
I assumed that MYSQL_ROOT_PASSWORD would be an environment variable that's set using ARG (e.g. Get environment variable value in Dockerfile ) however, looking at the DockerFile (https://github.com/docker-library/mysql/blob/696fc899126ae00771b5d87bdadae836e704ae7d/8.0/Dockerfile ) I don't see this ARG.
So, how is this root password being set?
It's actually used in the entrypoint script -
Ref - https://github.com/docker-library/mysql/blob/696fc899126ae00771b5d87bdadae836e704ae7d/8.0/docker-entrypoint.sh
Entrypoint config in Dockerfile -
COPY docker-entrypoint.sh /usr/local/bin/
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]
Let me clarify a bit about parameters in Dockerfile.
ARG - is only available during docker image build.
Let’s say, you want to store in docker image a hash commit of you source code.
ARG Commit
than you build a docker image:
docker build -t someimage —build-arg Commit=<somehash>
ENV - values that are available for docker containers and can be used as a part of RUN command.
On actual runtime, you can change ENV variable or add new env variables by adding it to run string:
docker run -e SOME_VAR=somevar someimage.
Hope this will help you.
I have a strange behavior with my Dockerfile. I try to make it write file with text coming from environment varibales :
FROM ubuntu:14.04
ENV KEY ''
ENV VAL ''
RUN echo "${KEY}:${VAL}" > /etc/test
CMD []
I built this image and run it like this :
docker run -it --rm -e KEY=aaa -e VAL=bbb mytest
If I display the /etc/test file, it is empty (it is present, but empty). It seems that when it creates the file, environment variables are not set.
Any idea?
Thank you
The command in the docker file RUN echo "${KEY}:${VAL}" > /etc/test is executed when you build the image using docker build ...
Thus this is logical, since at that point the env variables are empty.
You need to move the commad to the CMD command which will run when the image is started.
You can define KEY and VALUE as arguments and set their values when you're building the docker image.
FROM ubuntu:14.04
ARG KEY
ARG VAL
RUN echo "${KEY}:${VAL}" > /etc/test
CMD []
Then you can build the image using like this:
docker build --build-arg KEY=<value> --build-arg VAL=<value> .
https://docs.docker.com/engine/reference/builder/#using-arg-variables