Docker Community Forums

Share and learn in the Docker community.

Set environment path inside docker container

In windows, I have set an environment path to “D:\FFMPEG\bin” so that it is accessible in cmd. How can I do the same inside a docker container?

Attempt 1 - Inside docker file, I did - ENV PATH="D:\FFMPEG\bin:${PATH}". Also did
ENV PATH=".\FFMPEG\bin:${PATH}"
Attempt 2 - In my docker-compose.yml, I did -

env_file:
      - ./.env

my .env has - FFMPEG_PATH=./FFmpeg/bin

How can I set an environment path inside the container, like in windows?
Dockerfile

FROM python:3.8.5

ENV APP_HOME /app

WORKDIR $APP_HOME

COPY . /app

RUN apt-get update -y && apt-get install -y --no-install-recommends build-essential gcc libsndfile1

RUN pip install -r requirements.txt

RUN pip install python-dotenv

ENTRYPOINT ["python"]

CMD ["app.py"]

docker-compose.yml

version: "3.9"

services:

  web:

    build: .

    ports:

      - "5000:5000"

    volumes:

      - ".:/app"

    env_file:

      - ./.env

Folder structure

Heroku
  app.py
  Dockerfile
  docker-compose.yml
  FFMPEG
      bin
         ffmpeg.exe

Thank you.

ENV PATH="$PATH:$JAVA_HOME/bin" should do the job. (As an example)
But does "D:\FFMPEG\bin exist in your container? This looks like a windows path and most containers are linux containers.

1 Like
  1. The correct answer
    The best voted answer suggests to add ENV PATH “$PATH:/new/path” to the Dockerfile, and this should indeed work.

  2. So why doesn’t it work for me?
    As noted in some comments/answers, the solution 1. does not work for some people.

The reason is that the PATH can be overwritten by some script like .bashrc when running the docker container, giving thus the impression that the ENV PATH… did not work, but it theoretically did.

To solve the issue, you need to append to the .bashrc the correct PATH by adding the below command to your Dockerfile:

RUN echo “export PATH=/new/path:${PATH}” >> /root/.bashrc