現状
python3のプログラムをGCP(Ubuntu16.04)で実行した時は特に問題なく実行できたのですが、
Dockerで同じファイルを実行すると下記のエラーが表示されました。
'ascii' codec can't encode character '\uff1a' in position 11: ordinal not in range(128)
*GCPはDockerを使わないそのままの状態で利用しています。インスタンス作成時にインストールしたものなどは特にありません。
文字コードに関するエラーということは分かるのですがこちらを見ても解決方法がわかりませんでした。理解不足ですみません…
https://stackoverflow.com/questions/9942594/unicodeencodeerror-ascii-codec-cant-encode-character-u-xa0-in-position-20?rq=1&utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
仮説
GCPにはもともと用意(インストールや設定)されている何かがDockerから作成したUbuntuには含まれていないためにこういった問題が起こるのでしょうか?
課題・質問
上記の対策に書かれているようにプログラムを編集する方法もいいのですが、GCPでは動いているプログラムなのでプログラムを編集するよりDocker作成時に何かをインストールや設定をして解決したいと考えています。
(他の場所でもプログラムの変更が必要になったり、また別のプログラムを書くときに毎回このエラーのことを気にしながら書くのは大変なので…)
GCPと同じように文字コードのエラーを出さずに実行する方法はありますか?
インストールや設定することがあれば教えてください。
ご回答どうぞよろしくお願い致します。
Dockerfileは下記の通りです。
Dockerfile
1# Copyright 2013 Thatcher Peskens 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15FROM ubuntu:16.04 16 17MAINTAINER Dockerfiles 18 19# Install required packages and remove the apt packages cache when done. 20 21RUN apt-get update && \ 22 apt-get upgrade -y && \ 23 apt-get install -y \ 24 git \ 25 vim \ 26 cron \ 27 python3 \ 28 python3-dev \ 29 python3-setuptools \ 30 python3-pip \ 31 nginx \ 32 supervisor \ 33 sqlite3 && \ 34 pip3 install -U pip setuptools && \ 35 rm -rf /var/lib/apt/lists/* 36COPY ./crontab /etc/crontab 37 38# install uwsgi now because it takes a little while 39RUN pip3 install uwsgi 40 41# setup all the configfiles 42RUN echo "daemon off;" >> /etc/nginx/nginx.conf 43 44#for encode setting 45RUN echo "set encoding=utf-8;set fileencodings=iso-2022-jp,euc-jp,sjis,utf-8;" > ~/.vimrc 46RUN set fileformats=unix,dos,mac 47RUN source ~/.vimrc 48 49COPY nginx-app.conf /etc/nginx/sites-available/default 50COPY supervisor-app.conf /etc/supervisor/conf.d/ 51 52# COPY requirements.txt and RUN pip install BEFORE adding the rest of your code, this will cause Docker's caching mechanism 53# to prevent re-installing (all your) dependencies when you made a change a line or two in your app. 54 55COPY app/requirements.txt /home/docker/code/app/ 56RUN pip3 install -r /home/docker/code/app/requirements.txt 57 58# add (the rest of) our code 59COPY . /home/docker/code/ 60 61# install django, normally you would remove this step because your project would already 62# be installed in the code/app/ directory 63ENV PYTHONPATH /usr/bin/python3 64RUN cd /home/docker/code/app && /usr/bin/python3 manage.py collectstatic --no-input;/usr/bin/python3 manage.py migrate; 65 66 67EXPOSE 80 443 68CMD ["supervisord", "-n"]
[追記]
こちらの記事を参考にして、設定したところvimは文字化けしなくなったのですがPythonでは同じくエラーが出ました。
https://qiita.com/meio/items/08143eacd174ac0f7bd5
(vimの設定をしているので当然と言えば当然なのですが…)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/09 07:46
2018/05/09 07:57