- tl;dr
- ãªã, ãããªãã¨ã«ãªãã®ã
- ãªã, TTY ã®è¡æ«ã«ã¯ CRLF ãä»ä¸ããã¦ããã®ã
- åèæç®
tl;dr
ã®ã§ã¼ã 㧠Docker (docker-compose) ã使ã£ãã¡ãã£ã¨ããã³ãã³ãã©ã¤ã³ãã¼ã«ãä½ã£ãæã«, 以ä¸ã®ããã«å®è¡ãã¦æ¨æºåºåããã¡ã¤ã«ã«åºåããã¨, ä½æ
ã ^M
ã¨ããæ¹è¡ã³ã¼ã (Carriage Return) ãæ®ã£ã¦ãã¾ã£ã¦ãªãã§ãããã¨æã£ã¦èª¿ã¹ãã Docker ãªããããããã£ã¨ãã«ãã¸ã® TTY ã®è©±ã¾ã§æãä¸ãã£ã¦ãã¾ã£ã¦, ãããåå¼·ã«ãªã£ãã®ã§ã¡ã¢ã£ã¦ããã¾ã.
docker-compose run foo > foo.txt
foo.txt ã®ä¸èº«ã¯ä»¥ä¸ã®ãããªæãã«ãªã£ã¦ãã¾ãã¾ã.
[email protected]^M [email protected]^M [email protected]^M
ãªã, ãããªãã¨ã«ãªãã®ã
ã¾ãã«, 以ä¸ã® Issue ã«è¨è¼ããã¦ãã¾ãã.
ãã®ã³ã¡ã³ãã«å¯¾ããè¿çãå¼ç¨ãã¾ã.
Moral of the story, don't use -t unless you want a TTY. TTY line endings are CRLF, this is not Docker's doing.
TTY ãæå¹ã«ããå ´å, è¡æ«ã«ã¯ CRLF ãä»ä¸ãããã¨ã®ãã¨. ããã¦, ãã㯠Docker ã®ä»æ¥ã§ã¯ãªã, TTY ã®ä»æ¥ã§ããã¨ã®ãã¨. CRLF ãä»ä¸ããããã¨ãé¿ããããã°, TTY ãç¡å¹ (Docker ã§ã¯ããã©ã«ããç¡å¹ã ã, docker-compose ã§ã¯æå¹ã«ãªã£ã¦ãã) ã«ããã°è¯ãã¨ã®ãã¨.
ã»ãã»ã.
ä¸å¿, 確èªãã¦ã¿ã¾ã. ä¸è¨ã® Issue ã³ã¡ã³ãã«æ¸ããã¦ããæ¹æ³ãåèã«ã㦠od
ã³ãã³ããå©ç¨ãã¦ç¢ºèªãã¦ã¿ã¾ã. å°, 確èªã§å©ç¨ãã¦ããç°å¢ã¯ä»¥ä¸ã®éãã§ã.
$ docker version Client: Docker Engine - Community Version: 18.09.0 API version: 1.39 Go version: go1.10.4 Git commit: 4d60db4 Built: Wed Nov 7 00:47:43 2018 OS/Arch: darwin/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 18.09.0 API version: 1.39 (minimum version 1.12) Go version: go1.10.4 Git commit: 4d60db4 Built: Wed Nov 7 00:55:00 2018 OS/Arch: linux/amd64 Experimental: true $ docker-compose version docker-compose version 1.23.2, build 1110ad01 docker-py version: 3.6.0 CPython version: 3.6.6 OpenSSL version: OpenSSL 1.1.0h 27 Mar 2018
以ä¸, å®è¡çµæã§ã.
# Docker ã³ãã³ã㧠# TTY ç¡å¹ $ docker run ruby:2.5-alpine sh -c 'echo "test"' | od -c 0000000 t e s t \n 0000005 # TTY æå¹ $ docker run -t ruby:2.5-alpine sh -c 'echo "test"' | od -c 0000000 t e s t \r \n 0000006 # docker-compose ã³ãã³ã㧠# TTY ç¡å¹ (-T 㧠TTY ãç¡å¹ã«ãã) $ docker-compose run -T test sh -c 'echo "test"' | od -c 0000000 t e s t \n 0000005 # TTY æå¹ (docker-compose ã¯ããã©ã«ã㧠TTY ãæå¹ã«ãªã£ã¦ãã) $ docker-compose run test sh -c 'echo "test"' | od -c 0000000 t e s t \r \n 0000006
確ãã«, TTY ãç¡å¹ã«ãã¦ããå ´å, \n
ã®ã¿ã§ \r
ãä»ä¸ããã¦ããªããã¨ãå¤ãã¾ã.
ãªã, TTY ã®è¡æ«ã«ã¯ CRLF ãä»ä¸ããã¦ããã®ã
ãªã, TTY ã®è¡æ«ã«ã¯ CRLF ãä»ä¸ããã¦ããã®ã, 詳ããæç®ãè¦ã¤ãããã¨ãåºæ¥ãªãã£ãã®ã§ãã, 以ä¸ã®ãããªãscreen ã³ãã³ãã®åºåã¯ãªã㧠CRLF ãªãããï¼ãã¨ããè¨äºãè¦ã¤ããã®ã§è»¢è¼ãã¦ããã¾ã.
以ä¸, ã°ã¼ã°ã«ç¿»è¨³ããå 容ãä¸é¨æ訳ãã¤ãã¦è»¢è¼ããã¦é ãã¾ã.
The deep reason for the discrepancy between program output and a captured tty stream (e.g. typescript) is that tty's used to be printers.
ããã°ã©ã åºåã¨ãã£ããã£ããã tty ã¹ããªã¼ã ã¨ã®éãã¯, tty ãããªã³ã¿ã§ãã£ããã¨ã«ç±æ¥ãã.
Before unix, text always had a CRLF at the end of a line, not because it was considered to be the logical representation of a line termination, but because the characters individually had real physical meaning: move the print head all the way to the left, and advance the paper.
Unix ã®åã«ã¯, è¡çµç«¯ã«ã¯å¸¸ã« CRLF
ãä»ãã¦ãã. è¡çµç«¯ã®è«ççãªè¡¨ç¾ã¨ã¿ãªãããããã§ã¯ããã¾ããã§ããã, å®éã«ã¯ç´ãåé²ãããã¨ãã, ç©ççãªæå³ãããã¾ã.
Unix took a radical new approach: it treats text files on disk as a useful object in their own right (not just instructions for a printer), and lines as logical entities. The two-character line terminator is unnecessarily complicated in the unix worldview.
UNIX ã¯, ãã£ã¹ã¯ä¸ã®ããã¹ããã¡ã¤ã«ãããªã³ã¿ã®ããã®æ示ã ãã§ãªã, è«ççãªã¨ã³ãã£ãã£ã¨ãã¦æç¨ãªãªãã¸ã§ã¯ãã¨ãã¦æ±ã. 2 æåã®è¡çµç«¯æå (CRLF) ã¯, Unix ã®ä¸ç観ã§ã¯ä¸å¿ è¦ã«è¤éã§ãã.
But they had to work with existing hardware - printers and CRT dumb terminals that didn't recognize a single "end of line" character, but only a CR to do half the job and an LF to do the other half. So a translation had to be done, and it was done at the closest possible place to that hardware - in the tty driver.
ããã, æ¢åã®ãã¼ãã¦ã§ã¢ããªã³ã¿ãCRTãã 端æ«ã§ã¯,ãè¡æ«ãæåã¯èªèããã¾ããã§ããã, ã¸ã§ãã®ååãå®è¡ããCRã¨æ®ãã®ååãå®è¡ããLFã ããå¿ è¦ã§ãã. 翻訳ãå®äºããªããã°ãªããªãã£ãã®ã§, ãã㯠tty ãã©ã¤ãã®ä¸ã§ãã®ãã¼ãã¦ã§ã¢ã«æãè¿ãå¯è½ãªå ´æã§è¡ããã¾ãã.
Since then, it's all been backward compatibility. So you have a terminal emulator that insists on CRLF, and a tty driver that supplies it when a program outputs a newline.
ãã以æ¥, ããã¯ãã¹ã¦ä¸ä½äºææ§ãããã¾ã. ãããã£ã¦, CRLFã主張ãã端æ«ã¨ãã¥ã¬ã¼ã¿ã¨, ããã°ã©ã ãæ¹è¡ãåºåããã¨ãã«ãããä¾çµ¦ãã tty ãã©ã¤ããããã¾ã.
ã©ããã, æ´å²çãªçµç·¯ã®ä¸ã§ä¸ä½äºæã®ç¶æã®çº, TTY ã®è¡æ«ã«ã¯ CRLF ãä»ä¸ãããã®ã§ã¯ãªããã¨èªã¿åãã¾ãã. Linux ã®ã½ã¼ã¹ã³ã¼ãã¨ãèªãã° (èªããã°), ããå°ã確証ãæã¦ãæ å ±ãå¾ãããã®ã§ã¯ãªããã¨èãã¦ãã¾ãã, ããã¾ã§ã®æ å ±ã«ãã©ãçãã¾ã§ã« TTY ã CR, LF ã«ã¤ãã¦åèã«ãªãè¨äºãèªããã¨ãåºæ¥ã¾ãã.
ãããã¨ããããã¾ãã.