Last active
August 29, 2015 14:13
-
-
Save smile-0yen/c1450fe113d8253aa25e to your computer and use it in GitHub Desktop.
Dockerの基本操作をCentOS 7で確認 その3〜Dockerfileからイメージを作成〜 ref: http://qiita.com/smile-0yen/items/934907388cde9b29b8f7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# "#"で始まる行はコメント行とみなされます。 | |
# Dockerfileは必ずベースとなるイメージを指定するFROMから書きます。 | |
FROM ubuntu:14.04 | |
# MAINTAINERには文字通りDockerfile作成者を記載します。 | |
MAINTAINER smile-0yen smile0yen.1024@gmail.com | |
# RUNは指定されたコマンドをコンテナ内で実行し、結果をイメージとして保存します。 | |
RUN apt-get install ruby -y | |
# EXPOSEはコンテナの外に対して開くポートを指定します。 | |
# 親ホストのどのポートにマッピングするかはコンテナ起動時に決定します。 | |
EXPOSE 8080 | |
# WORKDIRによってこの行以降のRUN及びCMDを実行するディレクトリを指定できます。 | |
WORKDIR /opt | |
# CMDにはコンテナが起動したあとに実行されるコマンドを指定します。 | |
CMD ruby -run -e httpd . -p 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo docker build -t web_server . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{ | |
"Architecture": "amd64", | |
"Author": "smile-0yen smile0yen.1024@gmail.com", | |
"Comment": "", | |
"Config": { | |
"AttachStderr": false, | |
"AttachStdin": false, | |
"AttachStdout": false, | |
"Cmd": [ | |
"/bin/sh", | |
"-c", | |
"ruby -run -e httpd . -p 8080" | |
], | |
"CpuShares": 0, | |
"Cpuset": "", | |
"Domainname": "", | |
"Entrypoint": null, | |
"Env": [ | |
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" | |
], | |
"ExposedPorts": { | |
"8080/tcp": {} | |
}, | |
(以下略) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo docker images | |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE | |
web_server latest 455927c8e660 10 minutes ago 210 MB | |
(以下略) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo docker run -d -v /tmp/docker:/opt -p 80:8080 web_server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo docker ps | |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
fb5df2b423ea web_server:latest "/bin/sh -c 'ruby -r 18 minutes ago Up 18 minutes 0.0.0.0:80->8080/tcp boring_hopper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo docker logs --tail="3" fb5df | |
[2015-01-13 15:14:11] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true | |
10.0.2.2 - - [13/Jan/2015:15:14:11 UTC] "GET /test.txt HTTP/1.1" 304 0 | |
- -> /test.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo docker history web_server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo docker history web_server | |
IMAGE CREATED CREATED BY SIZE | |
455927c8e660 3 days ago /bin/sh -c #(nop) CMD [/bin/sh -c ruby -run - 0 B | |
9307eadf28da 3 days ago /bin/sh -c #(nop) WORKDIR /opt 0 B | |
c2bbe183f761 3 days ago /bin/sh -c #(nop) EXPOSE map[8080/tcp:{}] 0 B | |
c75722c696c8 3 days ago /bin/sh -c apt-get install ruby -y 17.29 MB | |
e82e1a53528e 3 days ago /bin/sh -c #(nop) MAINTAINER smile-0yen smile 0 B | |
ed5a78b7b42b 3 weeks ago /bin/sh -c #(nop) CMD [/bin/bash] 0 B | |
8c4b1edcceea 3 weeks ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/ 1.895 kB | |
9a4594fe74ea 3 weeks ago /bin/sh -c echo '#!/bin/sh' > /usr/sbin/polic 194.5 kB | |
fe95bf7d5f50 3 weeks ago /bin/sh -c #(nop) ADD file:c032cb16120c7533b5 192.5 MB | |
511136ea3c5a 19 months ago 0 B |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo docker history --no-trunc web_server | |
IMAGE CREATED CREATED BY SIZE | |
455927c8e6600f79ba6dda8e03709051a251a1dfb96f634b95959e8bfb0d5174 3 days ago /bin/sh -c #(nop) CMD [/bin/sh -c ruby -run -e httpd . -p 8080] 0 B | |
9307eadf28dadd4f21ea14024343c69de924d6766494fa73015aec8daf43ae1f 3 days ago /bin/sh -c #(nop) WORKDIR /opt 0 B | |
c2bbe183f7613773d0dc03670730acc2def499e85efa97074132698918a739d8 3 days ago /bin/sh -c #(nop) EXPOSE map[8080/tcp:{}] 0 B | |
c75722c696c8ecb42d8d9fc31f0b260845b881a59cc7881fe1761fc7360ba776 3 days ago /bin/sh -c apt-get install ruby -y 17.29 MB | |
e82e1a53528eaf869bca0a16ea9423853c077d06b0b1bfccfdd6a207790281f2 3 days ago /bin/sh -c #(nop) MAINTAINER smile-0yen smile0yen.1024@gmail.com 0 B | |
ed5a78b7b42bde1e3e4c2996e02da778882dca78f8919cbd0deb6694803edec3 3 weeks ago /bin/sh -c #(nop) CMD [/bin/bash] 0 B | |
8c4b1edcceea5c11f0a43de6c990036cffbd63f5590cba0075042c66cd90d948 3 weeks ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/\1/g' /etc/apt/sources.list 1.895 kB | |
9a4594fe74ea4c14e642b871556f1460f6d332350bf3c772e76ed0059444ff19 3 weeks ago /bin/sh -c echo '#!/bin/sh' > /usr/sbin/policy-rc.d && echo 'exit 101' >> /usr/sbin/policy-rc.d && chmod +x /usr/sbin/policy-rc.d && dpkg-divert --local --rename --add /sbin/initctl && cp -a /usr/sbin/policy-rc.d /sbin/initctl && sed -i 's/^exit.*/exit 0/' /sbin/initctl && echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup && echo 'DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' > /etc/apt/apt.conf.d/docker-clean && echo 'APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' >> /etc/apt/apt.conf.d/docker-clean && echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' >> /etc/apt/apt.conf.d/docker-clean && echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/docker-no-languages && echo 'Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/docker-gzip-indexes 194.5 kB | |
fe95bf7d5f5090fdaf5c5d442f9f05211f9cb338107a41ff10c7a46be4be2dea 3 weeks ago /bin/sh -c #(nop) ADD file:c032cb16120c7533b582d0c03b3e19314915f7674c000eda0cd36853005a880e in / 192.5 MB | |
511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158 19 months ago 0 B |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo docker inspect web_server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment