質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

解決済

1回答

571閲覧

GCP(Ubuntu16.04)とDocker(FROM ubuntu:16.04)の違いと文字コードエラーについて

Kirby2000

総合スコア24

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

0クリップ

投稿2018/05/09 04:56

編集2018/05/09 04:58

現状

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の設定をしているので当然と言えば当然なのですが…)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

確証はないですがLANG環境変数あたりじゃないかなぁと。

参考: https://qiita.com/YuukiMiyoshi/items/f389ea366060537b5cd9

投稿2018/05/09 05:45

YouheiSakurai

総合スコア6142

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問