gocha124の日記

ごちゃごちゃ書きます

Dockerの操作2

Docker Reigstoryのイメージを取得する。

[centos@ip-172-31-39-215 ~]$ sudo docker pull registry
Using default tag: latest
Trying to pull repository docker.io/library/registry ... 
latest: Pulling from docker.io/library/registry
486039affc0a: Pull complete 
ba51a3b098e6: Pull complete 
8bb4c43d6c8e: Pull complete 
6f5f453e5f2d: Pull complete 
42bc10b72f42: Pull complete 
Digest: sha256:7d081088e4bfd632a88e3f3bcd9e007ef44a796fddfe3261407a3f9f04abe1e7
Status: Downloaded newer image for docker.io/registry:latest
[centos@ip-172-31-39-215 ~]$ 

Docker ResistoryのImageが取得できている。

[centos@ip-172-31-39-215 ~]$ sudo docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
txcdb738/httpd              ver1.0              4ae50559bf03        25 hours ago        302 MB
docker.io/registry          latest              708bc6af7e5e        3 weeks ago         25.8 MB
docker.io/enakai00/centos   centos6             b8c94c5d2d7c        4 years ago         203 MB
docker.io/enakai00/centos   centos7             3bd78cf8ed76        4 years ago         172 MB
docker.io/enakai00/centos   latest              3bd78cf8ed76        4 years ago         172 MB

ローカルDocker Resitoryを起動する。

[centos@ip-172-31-39-215 ~]$ sudo docker run -d -p 5000:5000 registry
7eca1b83a6cdfb4914c90a2502c792507040ab41b84a8e5e72bd6b9a8f31d84e

[centos@ip-172-31-39-215 ~]$ sudo docker ps --format "{{.ID}}\t{{.Image}}\t{{.Ports}}"
7eca1b83a6cd	registry	0.0.0.0:5000->5000/tcp
[centos@ip-172-31-39-215 ~]$ sudo docker images

タグをはって、

[centos@ip-172-31-39-215 ~]$ sudo docker tag txcdb738/httpd:ver1.0 localhost:5000/txcdb738/httpd:ver1.0
[centos@ip-172-31-39-215 ~]$ sudo docker images txcdb738/httpd
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
txcdb738/httpd      ver1.0              4ae50559bf03        25 hours ago        302 MB
[centos@ip-172-31-39-215 ~]$ sudo docker images localhost:5000/txcdb738/httpd
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
localhost:5000/txcdb738/httpd   ver1.0              4ae50559bf03        25 hours ago        302 MB

ローカルRegistoryへプッシュする。

[centos@ip-172-31-39-215 ~]$ sudo docker push localhost:5000/txcdb738/httpd
The push refers to a repository [localhost:5000/txcdb738/httpd]
69b6f066ea18: Pushed 
5f70bf18a086: Pushed 
8d12f3483b2e: Pushed 
ver1.0: digest: sha256:5653e8ad82193dd6c34efe3dfb096b9d7041e2dffad53cac0b9b295ccba1fd50 size: 1153

Dockerfileを記述する。

[centos@ip-172-31-39-215 ~]$ vi ~/build_httpd/Dockerfile 
[centos@ip-172-31-39-215 ~]$ cat ~/build_httpd/Dockerfile 

FROM enakai00/centos:centos6
MAINTAINER txcdb738

RUN yum -y install httpd
ADD index.html /var/www/html/index.htlm
CMD service httpd start && bash

Dockerfileを使ってビルドする。

[centos@ip-172-31-39-215 ~]$ sudo docker build -t txcdb738/httpd:ver1.1 ~/build_httpd

ビルドしたイメージでhttpdを起動する。

[centos@ip-172-31-39-215 ~]$ sudo docker run -itd -p 8000:80 --name web01 txcdb738/httpd:ver1.1
5d7dbf821310d649bfac1df0d9b4e722b2cbb71135c5d251bca2c0e15a285661

dockerのログ

[centos@ip-172-31-39-215 ~]$ sudo docker logs web01
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3 for ServerName
                                                           [  OK  ]

停止して削除する。

[centos@ip-172-31-39-215 ~]$ sudo docker stop web01
web01
[centos@ip-172-31-39-215 ~]$ sudo docker rm web01
web01