概要

Ubuntu ローカル環境構築

$ vagrant box add trusty64 https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box
$ mkdir Docker
$ cd Docker
$ vagrant init trusty64
$ vi Vagrantfile
--------------------
config.vm.network "private_network", ip: "192.168.55.44"
--------------------
$ vagrant up
$ vagrant ssh

Dockerインストール

$ sudo apt-get update
$ sudo apt-get install \
    linux-image-extra-$(uname -r) \
    linux-image-extra-virtual
$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
/etc/apt/trusted.gpg
pub   4096R/0EBFCD88 2017-02-22
      Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <docker@docker.com>
sub   4096R/F273FCD8 2017-02-22
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
$ sudo apt-get update
$ sudo apt-get install docker-ce
$ sudo docker --version
Docker version 17.06.1-ce, build 874a737
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b04784fba78d: Pull complete
Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

Docker コマンドと基本コンポーネント

Image を操作

$ sudo docker search centos | more
$ sudo docker pull centos
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              328edcd84f1b        3 weeks ago         193MB
hello-world         latest              1815c82652c0        2 months ago        1.84kB
$ sudo docker inspect centos:latest
$ sudo docker inspect 328ed
$ sudo docker rmi 328ed

Container を操作してみよう

$ sudo docker run centos echo "hello world"
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED              STATUS                          PORTS               NAMES
354a27ea31e1        centos              "echo 'hello world'"   58 seconds ago       Exited (0) 58 seconds ago                           dazzling_feynman
450df998fddf        centos              "echo 'hello world'"   About a minute ago   Exited (0) About a minute ago                       quizzical_lalande
eef1eb757c2e        hello-world         "/hello"               37 minutes ago       Exited (0) 37 minutes ago                           sharp_agnesi
$ sudo docker ps -a -n=5
$ sudo docker rm eef
$ sudo docker ps -a

実行中の Container を操作

$ sudo docker run -d centos free -s 3
1fb08aae68483f2253ed8cb84f329b48d95edaba5e99ac490dab4c869b94b74c
$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
1fb08aae6848        centos              "free -s 3"         About a minute ago   Up About a minute                       gifted_murdock
$ sudo docker logs 1fb
$ sudo docker attach --sig-proxy=false 1fb
$ sudo docker kill 1fb
$ sudo docker start 1fb

Container から Image を作成

$ sudo docker run -i -t centos /bin/bash
[root@24b42c9b3ac1 /]# touch hello.txt
[root@24b42c9b3ac1 /]# exit
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
24b42c9b3ac1        centos              "/bin/bash"         3 minutes ago       Exited (0) 2 minutes ago                       nervous_ardinghelli
$ sudo docker commit 24b yuji/hello
$ sudo docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
yuji/hello                        latest              b378469ce2fc        24 seconds ago      193MB
$ sudo docker run -i -t yuji/hello /bin/bash
# ls hello.txt
hello.txt

Dockerfile の利用

$ vi Dockerfile
$ cat Dockerfile
FROM centos
MAINTAINER Yuji Shimojo <y.shimojo@example.com>
# RUN: build する時に実行
RUN echo "now building..."
# CMD: run する時に実行
# CMD echo "now running..."
CMD ["echo", "now running..."]
$ sudo docker build -t yuji/echo .
$ sudo docker run yuji/echo
now running...

Web サーバー起動

$ vi Dockerfile
FROM imagine10255/centos6-lnmp-php56
MAINTAINER Yuji Shimojo <y.shimojo@example.com>
RUN yum install -y httpd
ADD ./index.html /var/www/html/
EXPOSE 80
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
$ vi index.html
<html>
helllo from Docker!
</html>
$ sudo docker build -t yujishimojo/httpd .
$ sudo docker run -p 8080:80 -d yujishimojo/httpd

Image をプッシュ

$ sudo docker login
Username:
Password:
$ sudo docker push yujishimojo/httpd

Docker for Mac

Amazon Linux Image

$ docker search amazonlinux | more
$ docker pull amazonlinux
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
amazonlinux         latest              766ebb052d4f        4 months ago        162MB
$ docker run -i -t amazonlinux /bin/bash
# cat /etc/system-release
Amazon Linux AMI release 2017.03
# sudo yum repolist all
repo id          repo name          status
amzn-main/latest          amzn-main-Base          enabled: 5668
amzn-updates/latest          amzn-updates-Base          enabled:  776
# yum -y update
# date
Mon Aug 28 03:39:31 UTC 2017
# getenforce
bash: getenforce: command not found
# etc/init.d/iptables status
bash: etc/init.d/iptables: No such file or directory

Heroku Ruby Image

$ docker search heroku | more
$ docker pull heroku/ruby
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
heroku/ruby         latest              dc7ebd538ae6        4 months ago        1.47GB
$ docker run -i -t heroku/ruby /bin/bash
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS"
# git --version
git version 1.9.1
# ruby --version
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
# gem --version
2.4.5.1
# gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.5.1
  - RUBY VERSION: 2.2.3 (2015-08-18 patchlevel 173) [x86_64-linux]
  - INSTALLATION DIRECTORY: /app/heroku/ruby/bundle/ruby/2.2.0
  - RUBY EXECUTABLE: /app/heroku/ruby/ruby-2.2.3/bin/ruby
  - EXECUTABLE DIRECTORY: /app/heroku/ruby/bundle/ruby/2.2.0/bin
  - SPEC CACHE DIRECTORY: /root/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /app/vendor/ruby-2.2.3/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /app/heroku/ruby/bundle/ruby/2.2.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /app/user/bin
     - /app/heroku/ruby/bundle/ruby/2.2.0/bin
     - /app/heroku/ruby/node-0.12.7/bin
     - /app/heroku/ruby/ruby-2.2.3/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
# psql --version
psql (PostgreSQL) 9.5.5

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS