0

I have a small python app developed with docker containers.

My setup is:

Dockerfile

FROM python:3

ARG http_proxy
ARG https_proxy

ENV http_proxy ${http_proxy}
ENV https_proxy ${https_proxy}
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

RUN apt-get update
RUN apt install -y vim screen
RUN \
    echo 'alias py="/opt/venv/bin/python"' >> /root/.bashrc && \
    echo 'alias ls="ls --color=auto"' >> /root/.bashrc && \
    echo 'PS1="\u@\h:\[\e[33m\]\w\[\e[0m\]\$ "' >> /root/.bashrc
RUN python3 -m venv $VIRTUAL_ENV
WORKDIR /app   
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

docker-compose.yml

version: '3.8'

x-dev:
    &proxy_conf
    http_proxy: "${HTTP_PROXY}"
    https_proxy: "${HTTPS_PROXY}"
services:
    py_service:
        container_name: ${APP_NAME}
        build:
            context: .
            dockerfile: Dockerfile
            args: *proxy_conf
        image: ${APP_NAME}_img
        volumes:
        - '.:/app'
        restart: always
        command: tail -f /dev/null

.env

HTTP_PROXY=<http_proxy_server_here>
HTTPS_PROXY=<https_proxy_server_here>
APP_NAME=python_app

The problem is if the proxy server has changed i need to rebuild the image and i don't want that(as a last result maybe i will do it).

What i'm trying to do is change the proxy environment variables inside the container but i don't find the file where the env is stored.

The container OS version is:

[root@5b1b77079e10 ~ >>>] $ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

1 Answer 1

2

You should only need to recreate containers, not rebuild the image. I assume you are doing something like this to get everything up initially:

  1. docker-compose build
  2. docker-compose up -d

Then I assume you are updating you .env file, once you do that you should be able to just do the following for your container to pick up the change:

  1. docker-compose down
  2. docker-compose up -d

You should not need to do a docker-compose build again.

Sign up to request clarification or add additional context in comments.

7 Comments

You don't even need docker-compose down. docker-compose up -d is enough, the compose script will detect changes and recreate the container.
But proxy_server is stored in .env file and docker-compose up -d docker will recreate the image becouse something has changed. I am right ?
No, docker-compose up -d will only recreate the container not the image.
I don't have a another solution other than recreating container ? I am aware of the concept of ephemeral containers on docker, but i want to know where are stored the environments variable inside container.
Assuming we are talking about Linux containers then that is a linux question not really a docker question, but according to this they are stored in /proc/1/environ: forums.docker.com/t/where-are-stored-the-environment-variables/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.