Linux

Docker インストール CentOS7

 

CentOS7 のMinimalからDockerを入れて、
Software Design 2017年11月号 SQL50本ノックの実行環境を用意するまでの流れ。

 

# yum install -y yum-utils device-mapper-persistent-data lvm2

# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

 

# yum makecache fast


読み込んだプラグイン:fastestmirror
base                                                                                                           | 3.6 kB  00:00:00
docker-ce-stable                                                                                               | 2.9 kB  00:00:00
extras                                                                                                         | 3.4 kB  00:00:00
updates                                                                                                        | 3.4 kB  00:00:00
docker-ce-stable/x86_64/primary_db                                                                             |  10 kB  00:00:00
Loading mirror speeds from cached hostfile
 * base: ftp.nara.wide.ad.jp
 * extras: ftp.jaist.ac.jp
 * updates: ftp.jaist.ac.jp
メタデータのキャッシュを作成しました

 

# yum list docker-ce.x86_64 --showduplicates | sort -r

利用可能なパッケージ
読み込んだプラグイン:fastestmirror
docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
Loading mirror speeds from cached hostfile
 * updates: ftp.jaist.ac.jp
 * extras: ftp.jaist.ac.jp
 * base: ftp.nara.wide.ad.jp

 

バージョン指定する場合
# yum install docker-ce-17.06.0.ce-1.el7.centos

最新バージョンする場合
# sudo yum install docker-ce

 

# vi /etc/pam.d/su


#auth           required        pam_wheel.so use_uid

↓変更

auth            required        pam_wheel.so use_uid

 

 

# useradd yuu
# usermod -G wheel yuu

 

# visudo

%wheel  ALL=(ALL)       ALL
yuu     ALL=(ALL)   NOPASSWD: ALL

 

# su - yuu

[yuu@localhost ~]$ sudo usermod -aG docker $USER

 

$ sudo systemctl start docker
$ sudo systemctl enable docker

 

$ sudo docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
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/

 

$ sudo yum install wget unzip

 

$ wget http://image.gihyo.co.jp/assets/files/magazine/SD/2017/201711/download/env_script.zip

$ unzip env_script.zip

 

$ ls -laht

合計 20K
drwx------  3 yuu  yuu   123 12月  9 19:52 .
drwxrwxr-x  2 yuu  yuu    85 12月  9 19:52 env_script
-rw-------  1 yuu  yuu   128 12月  9 19:49 .bash_history
drwxr-xr-x. 3 root root   17 12月  9 19:43 ..
-rw-rw-r--  1 yuu  yuu  1.6K 10月 16 14:58 env_script.zip
-rw-r--r--  1 yuu  yuu    18  8月  3  2016 .bash_logout
-rw-r--r--  1 yuu  yuu   193  8月  3  2016 .bash_profile
-rw-r--r--  1 yuu  yuu   231  8月  3  2016 .bashrc

 

$ cd env_script

 

$ sudo sh postgres_initialize.sh


Error response from daemon: No such container: postgres_sd
Error response from daemon: No such container: psql_sd
906f85fce2e049424e4dc47227a762490e845f5148dbd8e02af3fbb92e67d7fe
Sending build context to Docker daemon  5.632kB
Step 1/5 : FROM postgres:9.6.5
9.6.5: Pulling from library/postgres
85b1f47fba49: Pull complete
2d4904bea61e: Pull complete
92fb981a71b7: Pull complete
4dda1edd3e9b: Pull complete
5ea002fc8280: Pull complete
feade6b1bbeb: Pull complete
16825a5c9040: Pull complete
a4101e46b1e2: Pull complete
078d6d550d3d: Pull complete
ac9086e062cf: Pull complete
7718e622f74c: Pull complete
111246a411c9: Pull complete
Digest: sha256:2f2b1f4d9d83db7378584d7f41b15a49b2cea25956af67698f8ea80e3bdc28ba
Status: Downloaded newer image for postgres:9.6.5
 ---> bd287e105bc1
Step 2/5 : RUN apt-get update &&   apt-get install -y wget unzip &&   wget https://ftp.postgresql.org/pub/projects/pgFoundry/dbsamples/pagila/pagila/pagila-0.10.1.zip -O /tmp/pagila-0.10.1.zip &&   unzip /tmp/pagila-0.10.1.zip -d /tmp &&   cat /tmp/pagila-0.10.1/pagila-schema.sql |   grep -v "CREATE PROCEDURAL LANGUAGE plpgsql" > /docker-entrypoint-initdb.d/pagila_init.sql &&   cat /tmp/pagila-0.10.1/pagila-data.sql >> /docker-entrypoint-initdb.d/pagila_init.sql
 ---> Running in 9e56af614e1f
Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB]
Get:2 http://security.debian.org jessie/updates/main amd64 Packages [598 kB]
Get:3 http://apt.postgresql.org jessie-pgdg InRelease [56.4 kB]
Ign http://deb.debian.org jessie InRelease
Get:4 http://deb.debian.org jessie-updates InRelease [145 kB]
Get:5 http://apt.postgresql.org jessie-pgdg/main amd64 Packages [149 kB]
Get:6 http://deb.debian.org jessie Release.gpg [2,373 B]
Get:7 http://apt.postgresql.org jessie-pgdg/9.6 amd64 Packages [1,699 B]
Get:8 http://deb.debian.org jessie-updates/main amd64 Packages [23.2 kB]
Get:9 http://deb.debian.org jessie Release [148 kB]
Get:10 http://deb.debian.org jessie/main amd64 Packages [9,063 kB]
Fetched 10.3 MB in 3s (3,037 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  ca-certificates libicu52 libidn11 libpsl0
Suggested packages:
  zip
The following NEW packages will be installed:
  ca-certificates libicu52 libidn11 libpsl0 unzip wget
0 upgraded, 6 newly installed, 0 to remove and 8 not upgraded.
Need to get 7,843 kB of archives.
After this operation, 31.8 MB of additional disk space will be used.
Get:1 http://security.debian.org/ jessie/updates/main wget amd64 1.16-1+deb8u4 [496 kB]
Get:2 http://deb.debian.org/debian/ jessie/main libidn11 amd64 1.29-1+deb8u2 [136 kB]
Get:3 http://deb.debian.org/debian/ jessie/main libicu52 amd64 52.1-8+deb8u5 [6,801 kB]
Get:4 http://deb.debian.org/debian/ jessie/main libpsl0 amd64 0.5.1-1 [41.6 kB]
Get:5 http://deb.debian.org/debian/ jessie/main ca-certificates all 20141019+deb8u3 [207 kB]
Get:6 http://deb.debian.org/debian/ jessie/main unzip amd64 6.0-16+deb8u3 [162 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 7,843 kB in 1s (4,538 kB/s)
Selecting previously unselected package libidn11:amd64.
(Reading database ... 12579 files and directories currently installed.)
Preparing to unpack .../libidn11_1.29-1+deb8u2_amd64.deb ...
Unpacking libidn11:amd64 (1.29-1+deb8u2) ...
Selecting previously unselected package libicu52:amd64.
Preparing to unpack .../libicu52_52.1-8+deb8u5_amd64.deb ...
Unpacking libicu52:amd64 (52.1-8+deb8u5) ...
Selecting previously unselected package libpsl0:amd64.
Preparing to unpack .../libpsl0_0.5.1-1_amd64.deb ...
Unpacking libpsl0:amd64 (0.5.1-1) ...
Selecting previously unselected package wget.
Preparing to unpack .../wget_1.16-1+deb8u4_amd64.deb ...
Unpacking wget (1.16-1+deb8u4) ...
Selecting previously unselected package ca-certificates.
Preparing to unpack .../ca-certificates_20141019+deb8u3_all.deb ...
Unpacking ca-certificates (20141019+deb8u3) ...
Selecting previously unselected package unzip.
Preparing to unpack .../unzip_6.0-16+deb8u3_amd64.deb ...
Unpacking unzip (6.0-16+deb8u3) ...
Processing triggers for mime-support (3.58) ...
Setting up libidn11:amd64 (1.29-1+deb8u2) ...
Setting up libicu52:amd64 (52.1-8+deb8u5) ...
Setting up libpsl0:amd64 (0.5.1-1) ...
Setting up wget (1.16-1+deb8u4) ...
Setting up ca-certificates (20141019+deb8u3) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
Updating certificates in /etc/ssl/certs... 174 added, 0 removed; done.
Setting up unzip (6.0-16+deb8u3) ...
Processing triggers for libc-bin (2.19-18+deb8u10) ...
Processing triggers for ca-certificates (20141019+deb8u3) ...
Updating certificates in /etc/ssl/certs... 0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d....done.
--2017-12-09 10:54:06--  https://ftp.postgresql.org/pub/projects/pgFoundry/dbsamples/pagila/pagila/pagila-0.10.1.zip
Resolving ftp.postgresql.org (ftp.postgresql.org)... 217.196.149.55, 87.238.57.227, 204.145.124.244, ...
Connecting to ftp.postgresql.org (ftp.postgresql.org)|217.196.149.55|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 633143 (618K) [application/zip]
Saving to: ‘/tmp/pagila-0.10.1.zip’

     0K .......... .......... .......... .......... ..........  8% 82.6K 7s
    50K .......... .......... .......... .......... .......... 16%  166K 5s
   100K .......... .......... .......... .......... .......... 24% 12.1M 3s
   150K .......... .......... .......... .......... .......... 32% 1.33M 2s
   200K .......... .......... .......... .......... .......... 40%  190K 2s
   250K .......... .......... .......... .......... .......... 48% 11.4M 1s
   300K .......... .......... .......... .......... .......... 56% 11.4M 1s
   350K .......... .......... .......... .......... .......... 64% 1.71M 1s
   400K .......... .......... .......... .......... .......... 72%  190K 1s
   450K .......... .......... .......... .......... .......... 80% 11.4M 0s
   500K .......... .......... .......... .......... .......... 88% 11.4M 0s
   550K .......... .......... .......... .......... .......... 97% 12.1M 0s
   600K ........Archive:  /tmp/pagila-0.10.1.zip
   creating: /tmp/pagila-0.10.1/
  inflating: /tmp/pagila-0.10.1/pagila-data.sql  .. ........                                   100% 17.5M=1.5s

2017-12-09 10:54:10 (406 KB/s) - ‘/tmp/pagila-0.10.1.zip’ saved [633143/633143]


  inflating: /tmp/pagila-0.10.1/pagila-insert-data.sql
  inflating: /tmp/pagila-0.10.1/pagila-schema.sql
  inflating: /tmp/pagila-0.10.1/README
 ---> bb4ce0b7e9ef
Removing intermediate container 9e56af614e1f
Step 3/5 : ENTRYPOINT docker-entrypoint.sh
 ---> Running in d1a11323700f
 ---> 2078ace4808b
Removing intermediate container d1a11323700f
Step 4/5 : EXPOSE 5432
 ---> Running in d7445535bb5c
 ---> 01b62712c78d
Removing intermediate container d7445535bb5c
Step 5/5 : CMD postgres
 ---> Running in 0a61f136c7ad
 ---> e5bc98de379a
Removing intermediate container 0a61f136c7ad
Successfully built e5bc98de379a
Successfully tagged postgres_sd:9.6.5
ae5b9cb511f22a372a96f310fba7fc44d6be888691f6c577564cfd910fd39fc7
9.6.5: Pulling from library/postgres
Digest: sha256:2f2b1f4d9d83db7378584d7f41b15a49b2cea25956af67698f8ea80e3bdc28ba
Status: Image is up to date for postgres:9.6.5

#================
# login postgres
#================
psql (9.6.5)
Type "help" for help.


postgres=#

 

Amazonおすすめ

iPad 9世代 2021年最新作

iPad 9世代出たから買い替え。安いぞ!🐱 初めてならiPad。Kindleを外で見るならiPad mini。ほとんどの人には通常のiPadをおすすめします><

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)