Docker packaging guide for Python

以下是一些关于python 集成docker 的文章,很不错

The basics

  1. Broken by default: why you should avoid most Dockerfile examples
    Most Dockerfile examples you’ll find on the Web are broken. And that’s a problem.
  2. A review of the official Dockerfile best practices: good, bad, and insecure
    The official Docker documentation’s Dockerfile best practices are mostly good—but they omit some important information.
  3. The best Docker base image for your Python application (January 2020)
    Ubuntu? Official Python images? Alpine Linux? Here’s how to choose a good base image.
  4. Alpine makes Python Docker builds 50× slower, and images 2× larger
    Alpine Linux is often recommended as a smaller, faster base image. But if you’re using Python, it will actually do the opposite.
  5. When to switch to Python 3.8
    Python 3.8 is out now—when should you start using it?
  6. Connection refused? Docker networking and how it impacts your image
    A command that runs fine on your computer may fail with connection refused when run in a container. You’ll learn why that happens, and how to prevent it.
  7. Faster or slower: the basics of Docker build caching
    Docker’s layer caching can speed up your image build—if you write your Dockerfile correctly.
  8. Installing system packages in Docker with minimal bloat
    Your Docker build needs to update system packages for security, and perhaps to install them for additional dependnecies. Here’s how to do it without making your image too large, on Debian, Ubuntu, CentOS and RHEL.

Security

  1. Avoiding insecure images from Docker build caching
    Docker’s layer caching is great for speeding up builds—but you need to be careful or it’ll cause you to have insecure dependencies.
  2. Less capabilities, more security: minimizing privilege escalation in Docker
    To reduce the security risk from your Docker image, you should run it as a non-root user. You should also reduce it capabilities: learn what, why, and how.
  3. Docker build secrets, the sneaky way
    When you’re building Docker images you often need some secrets: a password, an SSH key. For now, Docker lacks a good mechanism to pass in secrets in a secure way, which means you need to get sneaky.

Fast builds, small images

  1. The high cost of slow Docker builds
    A slow Docker build on the critical path for developer feedback is a lot more expensive than you think.
  2. Faster Docker builds with pipenv, poetry, or pip-tools
    Installing dependencies separately from your code allows you to take advantage of Docker’s layer caching. Here’s how to do it with pipenv, poetry, or pip-tools.
  3. Elegantly activating a virtualenv in a Dockerfile
    How to activate a virtualenv in a Dockerfile without repeating yourself—plus, you’ll learn what activating a virtualenv actually does.
  4. Multi-stage builds #1: Smaller images for compiled code
    You’re building a Docker image for a Python project with compiled code (C/C++/Rust/whatever), and somehow without quite realizing it you’ve created a Docker image that is 917MB… only 1MB of which is your code!
  5. Multi-stage builds #2: Python specifics—virtualenv, –user, and other methods
    Now that you understand multi-stage builds, here’s how to implement them for Python applications.
  6. Multi-stage builds #3: Why your build is surprisingly slow, and how to speed it up
    Multi-stage builds give you small images and fast builds—in theory. In practice, they require some tricks if you want your builds to actually be fast.

Applications and runtime

  1. Configuring Gunicorn for Docker
    Running in a container isn’t the same as running on a virtual machine or physical server: you need to configure Gunicorn (and other servers) appropriately.
  2. Activating a Conda environment in your Dockerfile
    Learn how to activate a conda environment in your Dockerfile.
  3. Decoupling database migrations from server startup: why and how
    It’s tempting to migrate your database schema when your application container starts up—here’s some reasons to rethink that choice.
  4. What’s running in production? Making your Docker images identifiable
    It’s difficult to debug production problems if you don’t know what image is running in production.
  5. A Python prompt into a running process: debugging with Manhole
    Your Python process is acting strange—wouldn’t it be useful to get a live Python interpreter prompt inside your running process?

Packaging as a process

  1. A thousand little details: developing software for ops
    Some thoughts on how to build software for ops, a domain that suffers from historical complexity and problem space complexity. And in particular, buildng a better way to do Docker packaging.
  2. Your Docker build needs a smoke test
    If you don’t test your Docker image before you push it, you’ll waste time (and maybe break production).

Products and Services

Production-ready template: best practices, faster

Instead of synthesizing every article above, spending days debugging your build process, and fighting slow builds, you can ship your Docker images with confidence—in just hours!—by using the Production-Ready Python Containers template.

原文地址:https://www.cnblogs.com/rongfengliang/p/12242412.html

时间: 2024-10-13 15:21:55

Docker packaging guide for Python的相关文章

Docker安装MySQL Tomcat Python Redis MongoDB Apache

Docker 安装 MySQL 方法一.docker pull mysql 查找Docker Hub上的mysql镜像 [email protected]:/mysql$ docker search mysql NAME                     DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED mysql                    MySQL is a wide

CentOS 7 Docker Installation Guide

Install 1. 查看系统版本 & 升级yum源 [[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) [[email protected] ~]# yum update 2. 安装docker [[email protected] ~]# yum install docker 3.启动docker deamon并将其设置成开机自启动[[email protected] ~]# 

python packaging

一.困惑 作为一个 Python 初学者,我在包管理上感到相当疑惑(嗯,是困惑).主要表现在下面几个方面: 这几个包管理工具有什么不同? * distutils * setuptools * distribute * disutils2 * distlib * pip 2. 什么时候该用pip,什么时候该用 setup.py ,它们有关系么? 3. easy_install . ez_setup.py . setup.py . setup.cfg 分别都是干啥的? 4. wheel 和 pip

使用docker安装部署Spark集群来训练CNN(含Python实例)

使用docker安装部署Spark集群来训练CNN(含Python实例) 本博客仅为作者记录笔记之用,不免有很多细节不对之处. 还望各位看官能够见谅,欢迎批评指正. 博客虽水,然亦博主之苦劳也. 如需转载,请附上本文链接,不甚感激! http://blog.csdn.net/cyh_24/article/details/49683221 实验室有4台神服务器,每台有8个tesla-GPU,然而平时做实验都只使用了其中的一个GPU,实在暴遣天物! 于是想用spark来把这些GPU都利用起来.听闻d

[Docker]在Python和IPython中使用Docker

现在Docker是地球上最炙手可热的项目之一,就意味着人民实际上不仅仅是因为这个才喜欢它. 话虽如此,我非常喜欢使用容器,服务发现以及所有被创造出的新趣的点子和领域来切换工作作为范例. 这个文章中我会简要介绍使用python中的docker-py模块来操作Docker 容器,这里会使用我喜爱的编程工具IPython. 安装docker-py 首先需要docker-py.注意这里的案例中我将会使用Ubuntu Trusty 14.04版本. $ pip install docker-py IPyh

docker build python环境时出现了个错误

前段时间面试,面试官问我除了简历这些你还有其他什么水平吗,我想了想我说我解决bug比普通人更好一些,然而面试官一脸不屑的跟我讲,解决bug呢更多的是需要经验,当时给我出了个问题是redis就是get不到,实际是有值的,这种bug怎么解,我说那就看日志了...反正说了一些思路,面试官予以否定.理由是找bug更多的是需要经验,当时也没什么可反驳的好像说的对,直到刚刚遇到了一个问题,在使用docker的时候build python相关的镜像,出现了如下错误 Get:9 http://archive.u

Docker 安装 Python

Docker 安装 Python 方法一.docker pull python:3.5 查找 Docker Hub 上的 python 镜像: docker search python 这里我们拉取官方的镜像,标签为3.5 : docker pull python:3.5 等待下载完成后,我们就可以在本地镜像列表里查到 REPOSITORY 为 python ,标签为3.5的镜像: docker images | grep python 方法二.通过 Dockerfile 构建 创建Docker

使用Docker构建基于centos7镜像的python环境

Dcokerfile配置信息 ############################################## # 基于centos7构建python3运行环境 # 构建命令: 在Dockerfile文件目录下执行 docker build -t python-centos:3.5 . # 容器启动命令: docker run -itd --name python --restart always --privileged=true -v /root/dockers/python:/

[转载]Python 包管理工具解惑

原文链接:http://zengrong.net/post/2169.htm Python 包管理工具解惑 python packaging 一.困惑 作为一个 Python 初学者,我在包管理上感到相当疑惑(嗯,是困惑).主要表现在下面几个方面: 这几个包管理工具有什么不同? distutils setuptools distribute disutils2 distlib pip 什么时候该用pip,什么时候该用 setup.py ,它们有关系么? easy_install.ez_setup