"Création d'un service qui modifie l'historique d'utilisation de Suica mobile afin qu'il puisse être facilement utilisé pour le règlement des dépenses" Tout d'abord, nous allons développer en Python, donc créer un environnement où Python peut être exécuté
windows PC (Core i7-7600 / 16GB) Modifier avec VS code Il est pratique d'inclure les extensions Python et Docker
Puisqu'il est développé sur un PC Windows, il est difficile de le faire directement. L'environnement d'exécution Python configure un conteneur avec Docker
Installez ** Docker pour Windows ** Il est nécessaire d'activer Hyper-V. Installez également [** docker-compose **] * [Docker] Installer Docker et Docker Compose sur Windows 10 Professionnel 64 bits
Je vais installer diverses choses, alors construisez l'image Enregistrez le fichier suivant en tant que Dockerfile dans un répertoire approprié quelque part
Dockerfile
FROM centos/python-36-centos7:latest
USER root
RUN yum -y install java-1.8.0-openjdk
RUN pip install flask pandas tabula-py uwsgi
WORKDIR /src
ENV PYTHONUNBUFFERED=1
Puisque vous modifiez le fichier Python sous Windows et que vous l'exécutez sur Docker, vous devez pouvoir voir le fichier Python sous Windows à partir du conteneur. Cela peut être spécifié avec "-v" lors du lancement du conteneur, mais comme Windows est gênant et que je ne veux pas taper la commande à chaque fois, unifiez les commandes avec docker-compose
docker-compose.yml
version: '3.7'
services:
  testenv:
    build:
      context: ./app
      dockerfile: Dockerfile
    container_name: testenv
    tty: true
    command: /bin/sh -c "while :; do sleep 10; done"
    volumes:
      - ./app/src:/src
volumes:
  temp:
S'il n'y a pas de commande: part, le conteneur tombera en un instant Quand je google, la plupart des gens le résolvent avec tty: vrai, mais pour une raison quelconque, il est inutile dans mon environnement
Placez le Dockerfile et le docker-compose.yml comme ceci test.py est un fichier Python à exécuter
│  docker-compose.yml
│
└─app
    │  Dockerfile
    │
    └─src
            test.py
$ docker-compose.exe up --build -d
Creating network "test_default" with the default driver
Building testenv
Step 1/6 : FROM centos/python-36-centos7:latest
 ---> 90c6a4022ee5
Step 2/6 : USER root
 ---> Using cache
 ---> 03e9f59a6dbc
Step 3/6 : RUN yum -y install java-1.8.0-openjdk
 ---> Using cache
 ---> 463337c7b050
Step 4/6 : RUN pip install flask pandas tabula-py PyPDF2 uwsgi crontab
 ---> Using cache
 ---> 26c28d2b838c
Step 5/6 : WORKDIR /src
 ---> Running in f5ab2a9b405e
Removing intermediate container f5ab2a9b405e
 ---> b998a42b8180
Step 6/6 : ENV PYTHONUNBUFFERED=1
 ---> Running in fd8d783f9e2f
Removing intermediate container fd8d783f9e2f
 ---> e1e0833bc33a
Successfully built e1e0833bc33a
Successfully tagged test_testenv:latest
Regarde si tu t'es levé
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
3b7e97ef1fd5        test_testenv        "container-entrypoin…"   4 seconds ago       Up 2 seconds        8080/tcp            testenv
Essayez d'entrer dans le conteneur
$ winpty docker exec -it testenv bash
(app-root) bash-4.2# pwd
/src
(app-root) bash-4.2# ls
test.py
(app-root) bash-4.2# cat test.py
print('Hello, World')
(app-root) bash-4.2# python3 test.py
Hello, World
Vous pouvez enfin commencer à écrire votre code.
Recommended Posts