pull image
先pull兩個image:
python:3.9.5-slim
docker image pull python:3.9.5-slim
redis
docker image pull redis
新增2個dockerfile
FROM python:3.9.5-slim
RUN pip install flask redis && \
groupadd -r flask && useradd -r -g flask flask && \
mkdir /src && \
chown -R flask:flask /src
USER flask
COPY startup.py /src/startup.py
WORKDIR /src
ENV FLASK_APP=startup.py REDIS_HOST=redis
#EXPOSE 5000
CMD ["flask", "run", "-h", "0.0.0.0"]
用上方的dockerfile build image,註解掉EXPOSE的image名為flask-demo:
docker image build -t flask-demo .
再建立一個image,這個image只是把EXPOSE 5000打開。
FROM python:3.9.5-slim
RUN pip install flask redis && \
groupadd -r flask && useradd -r -g flask flask && \
mkdir /src && \
chown -R flask:flask /src
USER flask
COPY startup.py /src/startup.py
WORKDIR /src
ENV FLASK_APP=startup.py REDIS_HOST=redis
EXPOSE 5000
CMD ["flask", "run", "-h", "0.0.0.0"]
打開EXPOSE的image名為flask-demo-new。
docker image build -t flask-demo-new .
建立後查看image
docker image inspect flask-demo
docker image inspect flask-demo-new
裡面的Config只有flask-demo-new的有多出
"ExposedPorts": {
"5000/tcp": {}
},