freyta / 7Eleven-Python

A python script to check fuel prices and also lock them in
GNU General Public License v3.0
128 stars 63 forks source link

Updated Dockerfile to best practice #46

Closed beaudeanadams closed 4 years ago

beaudeanadams commented 4 years ago

Using ENV in docker file Using EXPOSE in docker file Updated Python Version to 3.8

MattKobayashi commented 4 years ago

I'm concerned about putting ENV variables and EXPOSE into the Dockerfile.

beaudeanadams commented 4 years ago

I'm concerned about putting ENV variables and EXPOSE into the Dockerfile.

* AFAIK once ENV variables are set in the Dockerfile, you cannot override those variables with different ones at runtime. Happy to be proven wrong on this though.

Unfortunately the Docker Documentation doesn't specify this, however, all ENV variables can and will be overridden if you specify the it using the -e parameter when you use docker run or docker create for the docker container.. I'm using this myself for the TZ environment variable for instance. It's set as UTC in the dockerfile, but I'm using Australia/Brisbane when it's created.

* It's not always going to be the case that someone wants to expose the ports outside of the Docker network (e.g. I use a reverse proxy to gain access to my containers from outside). Forcing the port to be exposed as part of the constructed image removes that flexibility from users.

Luckily thats not the case. As per the Docker documentation it states:

The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published. To actually publish the port when running the container, use the -p flag on docker run to publish and map one or more ports, or the -P flag to publish all exposed ports and map them to high-order ports.

MattKobayashi commented 4 years ago

In that case, I stand thoroughly corrected! :)