###概要
- 軽量な仮想化環境
- Build once, run anywhere
###環境
- Ubuntu(Vagrant) <- Docker
###目的
- 久しぶりに見てみたら、Docker CEのインストール方法が変わっていたのでメモ書き
###手順
Ubuntuの用意(boxの追加)
www.vagrantbox.es
にリストがある。
ここで希望に沿ったboxのurlをコピー
$ vagrant box add amd64 https://cloud-images.ubuntu.com/xenial/ current/xenial-server-cloudimg-amd64-vagrant.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'amd64' (v0) for provider:
box: Downloading: https://cloud-images.ubuntu.com/xenial/current/ xenial-server-cloudimg-amd64-vagrant.box
==> box: Successfully added box 'amd64' (v0) for 'virtualbox'!
ディレクトリ作成
`$ mkdir Docker`
`$ vagrant init amd64`
ipを変更(Vagrantfile)
Docker/Vagrantfile
28 # Create a forwarded port mapping which allows access to a specific port
29 # within the machine from a port on the host machine and only allow access
30 # via 127.0.0.1 to disable public access
31 # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
32
33 # Create a private network, which allows host-only access to the machine
34 # using a specific IP.
35 # config.vm.network "private_network", ip: "192.168.55.44"
36
37 # Create a public network, which generally matched to bridged network.
38 # Bridged networks make the machine appear as another physical device on
39 # your network.
ここで
$ vagrant up
結構時間をかけてこんな感じの画面になる。
そこから
$ vagrant ssh
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-112-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
0 packages can be updated.
0 updates are security updates.
vagrant@ubuntu-xenial:~$
こんな感じでubuntu環境にうまく入る。
Dockerの導入
####repositoryセットアップ
-
aptパッケージのシステム更新をする
vagrant@ubuntu-xenial:/home$ sudo apt-get update Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB] Get:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB] Fetched 24.5 MB in 15s (1,561 kB/s) Reading package lists... Done
-
Install packages to allow apt to use a repository over HTTPS:(aptがhttpsを超えてのリポジトリ利用を許可)
vagrant@ubuntu-xenial:/home $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
後に出てくるのを全てY選択
-
Add Docker’s official GPG key:(GPGキーの追加)
vagrant@ubuntu-xenial:/home$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - OK
-
Use the following command to set up the stable repository. You always need the stable repository, even if you want to install builds from the edge or test repositories as well. To add the edge or test repository, add the word edge or test (or both) after the word stable in the commands below.
$ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
####Docker CEのインストール
-
sudo apt-get update
sudo apt-get update
-
最新版のDocker CEのインストール
sudo apt-get install docker-ce
-
バージョン確認
vagrant@ubuntu-xenial:/home$ docker --version Docker version 17.12.0-ce, build c97c6d6
-
なんか出てきた
vagrant@ubuntu-xenial:/home$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest:
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.
(amd64)
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/