gocha124の日記

ごちゃごちゃ書きます

Dockerの操作

基本操作めも

[centos@ip-172-31-39-215 ~]$ sudo yum -y install net-tools
[centos@ip-172-31-39-215 ~]$ sudo yum -y update
[centos@ip-172-31-39-215 ~]$ sudo reboot
[centos@ip-172-31-39-215 ~]$ sudo systemctl stop firewalld.service
Failed to stop firewalld.service: Unit firewalld.service not loaded.
[centos@ip-172-31-39-215 ~]$ sudo systemctl mask firewalld.service
Created symlink from /etc/systemd/system/firewalld.service to /dev/null.
[centos@ip-172-31-39-215 ~]$ sudo yum -y install docker
[centos@ip-172-31-39-215 ~]$ sudo systemctl enable docker.service
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[centos@ip-172-31-39-215 ~]$ sudo systemctl start docker.service
[centos@ip-172-31-39-215 ~]$ sudo docker search enakai00
[centos@ip-172-31-39-215 ~]$ sudo docker pull -a enakai00/centos
[centos@ip-172-31-39-215 ~]$ sudo docker images
[centos@ip-172-31-39-215 ~]$ sudo docker run -it --name centos01 enakai00/centos:centos6 /bin/bash
[root@b6cf0659e158 /]# df -h /
Filesystem      Size  Used Avail Use% Mounted on
overlay         8.0G  2.0G  6.1G  24% /
[root@b6cf0659e158 /]# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 15:05 ?        00:00:00 /bin/bash
root        16     1  0 15:07 ?        00:00:00 ps -ef
[root@b6cf0659e158 /]# ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:AC:11:00:02  
          inet addr:172.17.0.2  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1312 (1.2 KiB)  TX bytes:656 (656.0 b)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@b6cf0659e158 /]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.17.0.1      0.0.0.0         UG    0      0        0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0
[centos@ip-172-31-39-215 ~]$ sudo docker ps
[centos@ip-172-31-39-215 ~]$ sudo docker attach centos01
[root@b6cf0659e158 /]# yum -y install httpd
[centos@ip-172-31-39-215 ~]$ sudo docker stop centos01
[centos@ip-172-31-39-215 ~]$ sudo docker ps -a
CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS                       PORTS               NAMES
b6cf0659e158        enakai00/centos:centos6   "/bin/bash"         5 minutes ago       Exited (137) 8 seconds ago                       centos01
[centos@ip-172-31-39-215 ~]$ sudo docker start centos01
centos01
[centos@ip-172-31-39-215 ~]$ sudo docker commit centos01 txcdb738/httpd:ver1.0
sha256:4ae50559bf0383c33c34800b3ef50d7a0455a9c29f445f387ae2e4a12b4bc3a3
[centos@ip-172-31-39-215 ~]$ sudo docker images txcdb738/httpd
[centos@ip-172-31-39-215 ~]$ sudo docker attach centos01
[centos@ip-172-31-39-215 ~]$ sudo docker run -it -p 8000:80 --name web01 txcdb738/httpd:ver1.0 /bin/bash
[root@03f2fdf05c94 /]# 
[root@03f2fdf05c94 /]# echo '<h1>Hello, Docker!</h1>' > /var/www/html/index.html
[root@03f2fdf05c94 /]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2 for ServerName
                                                           [  OK  ]
[root@03f2fdf05c94 /]# 
[centos@ip-172-31-39-215 ~]$