Use the same Dockerfile – please
As Containers have progressed, Docker has stood out as the defacto standard. As many of the laggards are coming up to speed, Dockerfiles can be seen in many open source repositories. With the addition to that, I have seen a few repos with a Dockerfile-prod
, Dockerfile-dev
, Dockerfile-test
, etc.
Additionally, you find an IF clause in the CMD
statement such as:
CMD if [ "$REACT_NODE_ENV" = "development" ]; \
then yarn dev; \
else yarn build && yarn start --only=production; \
fi
To those repositories, I have one daunting question:
WHY?
Container start commands can be overwritten at run time. Here is how to do it:
# Dockerfile
FROM alpine:3.6
CMD echo "production start command"
# docker-compose.yml
version: '3'
services:
dev-server:
build: .
command: echo 'development start command'
# kubernetes-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: cool-app
namespace: cool-app-testing
labels:
app: cool-app
spec:
replicas: 1
selector:
matchLabels:
app: cool-app
template:
metadata:
labels:
app: cool-app
spec:
containers:
- name: cool-app
image: alpine:3.6
command:
- echo
- 'testing start command'