# Docker: ARGuments and ENVironments Variables
###### tags: `Docker`

[TOC]
# Why we need them?
Allow us to create more flexible images and containers, as we do not need to hard code in containers and images. We can **set variables up dynamically, when we set image or run container**.
# **ENV**ironments
Taking this as example, **port 80** is hard coded here.
``` === Javascript
app.listen(80);
```
We could change it as:
``` === Javascript
//Server.js
app.listen(process.env.PORT);
```
``` ===
//Dockerfile
ENV PORT 80
EXPOSE $PORT
```
``` ===
//--env PORT=8000 changes the PORT ENV variable to 8000, that is why we changed to 3000:8000 instead of 3000:80
//--env can be shortened to -e
docker run -d --rm -p 3000:8000 --env PORT=8000 --name feedbackapp -v feedback:/app/feedback -v "C:/Users/Claudia/Downloads/data-volumes-01-starting-setup/data-volumes-01-starting-setup:/app" -v /app/node_modules feedback:volume
```
# **ARG**uments
We set up our arguments in our Dockerfile and when we need to build image, we can directly just change the image according to what we want.
``` ===
//Dockerfile
ARG DEFAULT_PORT=80
ENV PORT ${DEFAULT_PORT}
EXPOSE $PORT
```
```===
<!---Using -build-arg we can change arguments when building images-->
docker build -t feedback:dev --build-arg DEFAULT_PORT=8000 .
```