Skip to content

[Bug]: Environment variables can be duplicated on run #1212

Open

Description

@natevw

I have done the following

  • I have searched the existing issues
  • If possible, I've reproduced the issue using the 'main' branch of this project

Steps to reproduce

container run does not fully override environment variables of the underlying image.

  1. provide a default ENV variable in a Dockerfile (e.g. https://github.com/alpine-docker/ollama/blob/e92f203364ee4f5dafc00115cc23fc68a5bfb8a4/Dockerfile#L17-L18)
  2. attempt to override it when running the image e.g. container run -e OLLAMA_HOST=ollama.local:11434 alpine/ollama ps
  3. the executable does not behave as though the variable is set (in this case it complains "Error: could not connect to ollama server, run 'ollama serve' to start it")

Current behavior

The reason can be seen by inspecting the container's environment via e.g. container run -e OLLAMA_HOST=ollama.local:11434 --entrypoint=/usr/bin/env alpine/ollama which reveals:

PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
OLLAMA_HOST=0.0.0.0
OLLAMA_HOST=ollama.local:11434
HOME=/root

so when the normal entrypoint calls some equivalent of getenv("OLLAMA_HOST") it receives the value of the first entry rather than the last.

Note that this behavior is masked by any intervening shell. For example running container run -e OLLAMA_HOST=ollama.local:11434 --entrypoint=/bin/sh alpine/ollama -c env outputs the actually-desired outcome instead:

SHLVL=1
HOME=/root
OLLAMA_HOST=ollama.local:11434
SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
PWD=/

I'm assuming sh (or perhaps any intervening process) must have the effect of cleaning up its environment and removing the duplicates.

Expected behavior

The output of docker run -e OLLAMA_HOST=ollama.local:11434 --entrypoint=/usr/bin/env alpine/ollama is simply:

PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
HOSTNAME=d64b91a7b258
TERM=xterm
OLLAMA_HOST=ollama.local:11434
SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
HOME=/root

i.e. with only the version of OLLAMA_HOST from the invocation, not from the Dockerfile.

Environment

- OS: 
- Xcode: 
- Container:

Relevant log output

N/A

Code of Conduct

  • I agree to follow this project's Code of Conduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions