24 Apr 2020
使用 Docker 建立开发环境
Why Docker
我有洁癖,不想让混乱的环境依赖污染日常使用的系统;
可以第一时间享受到新版本的快乐,比如很早就用上python3.8;
部署极其方便,项目无痛上线;
Dockerfile
Dockerfile 是指挥容器运作的配置文件,在里面可以配置container使用什么操作系统,提前安装哪些 sdk
FROM centos:8
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN yum install -y python3 python3-devel net-tools wget cronie vim gcc gcc-c++ autoconf
COPY requirements.txt /tmp/requirements.txt
RUN pip3 install --upgrade pip setuptools -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip3 install -r /tmp/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
WORKDIR /home/app
EXPOSE 3000
this dockerfile from my project bitcoin python: Link
常用命令
image shell
docker run -it --entrypoint /bin/sh <image-id>
container shell
docker exec -it fdffcb69b7a4 bash
docker-compose
docker container ls
docker rm
docker-compose -f docker-compose.dev.yml build
docker-compose -f compose.dev.yml run centos8_python_dev
# 删除全部container
docker container prune
了解更多
Set specific IP addresses to docker containers created with docker-compose
Dockerize your Python Application