Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove an ENV setting from a docker image

Tags:

docker

I have a docker image which sets HOME and PATH:

[{
  ...
  "config": {
    "HOME=/",
  }
  ...

I know I can replace it, but is it possible to remove it (and let the normal bash profile settings be used instead). I'd prefer not to hack the shell profile files to override it.

like image 809
Vitaly Kushner Avatar asked Sep 23 '13 05:09

Vitaly Kushner


People also ask

How do I unset an environment variable in Dockerfile?

If you still want to use ENV to set your variable, then you'll have to start each RUN in which you want the variable to be unset with unset VAR_NAME , which will unset it for that specific RUN only.

Where are docker ENV stored?

It's not stored (in a file) anywhere. It's passed from Docker to the process running in the container.

Does docker use .ENV file?

. env files are for docker-compose. You need to use the docker-compose cli instead of just docker .


1 Answers

I couldn't get @creack's answer to work for me.

In my case I had inadvertently committed some environment variables to an image and I wanted to remove them from the image.

I ended up launching the image and 'unsetting' the environment variable by using -e option with no value for the variable,

For example to unset the environment variable FOO

docker run -it -e FOO IMAGE /bin/bash

Then commit the container

docker commit -m 'removed FOO' CONTAINER_ID IMAGE

like image 149
Alex Soto Avatar answered Sep 24 '22 08:09

Alex Soto