Python environment with docker-compose

Introduction

As soon as I wanted a container that could specify the version of python. (Mainly due to icrawler) I decided to try using docker-compose because it is easy to throw away if it is made in a container and it is easy to manage ports.

Preparation

Create files and folders.

$ mkdir python
$ cd python
$ touch Dockerfile
$ touch docker-compose.yml
$ touch requirements.txt //Write down the package you want to put in
$ mkdir workspace

If there is a way to make the authority to be root when volume is done from inside the container, please let me know.

Dockerfile


FROM python:3.6

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

ARG DOCKER_UID=1000
ARG DOCKER_USER=docker-user
RUN useradd -m --uid ${DOCKER_UID} --groups sudo ${DOCKER_USER}

USER ${DOCKER_USER}

WORKDIR /home/docker-user

docker-compose.yml


version: "3"
services:
  python36:
    build: .
    container_name: python36
    ports:
      - "5000:5000"
    tty: true
    volumes:
      - ./workspace:/home/docker-user

The preparation is complete.

Set up a container

Build a container. Then just enter.

$ docker-compose build
$ docker-compose up -d

#How to enter
$ docker-compose exec python36 bash

#When entering as root
$ docker-compose exec --user=root python36 bash

As a commitment, I do not operate it as root. Just note that I can't say anything because I don't know how to write it.

reference

Docker hub Bulk installation of packages using requirements.txt with Python and pip

Recommended Posts

Python environment with docker-compose
Virtual environment with Python 3.6
Install Python environment with Anaconda
Manage python environment with virtualenv
Build python3 environment with ubuntu 16.04
Build python environment with direnv
Get started with Python! ~ ① Environment construction ~
Build python virtual environment with virtualenv
Build Mysql + Python environment with docker
Create a virtual environment with Python!
Building a virtual environment with Python 3
Python3 environment construction with pyenv-virtualenv (CentOS 7.3)
pytorch @ python3.8 environment construction with pipenv
Prepare Python development environment with Atom
Statistics with python
Python environment construction
python environment settings
Python with Go
python windows environment
Environment construction (python)
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
python environment construction
with syntax (Python)
Python --Environment construction
Bingo with python
Zundokokiyoshi with python
Python environment construction
python environment construction
Excel with Python
Microcomputer with Python
Cast with python
[Pyenv] Building a python environment with ubuntu 16.04
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
[Python] Building an environment with Anaconda [Mac]
Change Python 64bit environment to 32bit environment with Anaconda
Building a Python3 environment with Amazon Linux2
Build Jupyter Lab (Python) environment with Docker
[Development environment] Python with Xcode [With screen transition]
Use smbus with python3 under pyenv environment
Note when creating an environment with python
[Python] Create a virtual environment with Anaconda
Build a Fast API environment with docker-compose
Create Python + uWSGI + Nginx environment with Docker
Build Python environment with Anaconda on Mac
Launch environment with LineBot + Heroku + Docker + Python
Build a python virtual environment with pyenv
Clean python environment with pythonz and virtualenv
Build a modern Python environment with Neovim
Let's get along with Python # 0 (Environment construction)
Build AI / machine learning environment with Python
Introduced sip-4.14 in python3.2.2 environment with MacOS 10.7.4
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Collecting information from Twitter with Python (Environment construction)