LoginSignup
2
0

More than 3 years have passed since last update.

すぐできるDokerサンプルにpythonを追加した

Last updated at Posted at 2019-09-02

知り合いがpythonを触りたいとうことで、
すぐできるDockerサンプルにもpythonの2系と3系を追加した。

追加したやつ

pythonを追加

directory
~/
  docker-compose.yaml
  php_sample.php
  python_sample.py
  ruby_sample.rb
docker-compose.yaml
~略~
  python3.7: # docker-compose run python3.7
    image: python:3.7
    volumes:
      - ./python_sample.py:/python_sample.py
    command: python python_sample.py
  python2.7: # docker-compose run python2.7
    image: python:2.7
    volumes:
      - ./python_sample.py:/python_sample.py
    command: python python_sample.py
python_sample.py
# -*- coding: utf-8 -*-

import platform

print(platform.python_version())
print('パイソンだよ')

実行結果

sh
$ docker-compose run python2.7

2.7.16
パイソンだよ
sh
$ docker-compose run python3.7

3.7.4
パイソンだよ

 終わり

ちなみに、# -*- coding: utf-8 -*- は、
3.7では無くても怒られなかったが、2.7では、怒られた。

sh
$ docker-compose run python2.7

  File "python_sample.py", line 4
SyntaxError: Non-ASCII character '\xe3' in file python_sample.py on line 4, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0