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.
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.
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.
Docker hub Bulk installation of packages using requirements.txt with Python and pip
Recommended Posts