Post

Docker - basic web site by docker

basic web site by docker


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
docker run -it --name a-container alpine
docker exec a-container apk add nginx

docker cp a-container:/etc/nginx/conf.d/default.conf .
vim default.conf
# server {
# 	listen 80 default_server;
# 	listen [::]:80 default_server;
#   root /var/www/;
# }

docker cp default.conf a-container:/etc/nginx/conf.d/default.conf


~ $ docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
f9f7eb278e81        alpine              "/bin/sh"           17 minutes ago      Up 16 minutes                           web01


~ $ vim index.html
# hello world!!

~ $ docker cp index.html web01:/var/www
~ $ docker exec -dt web01 nginx -g 'pid /tmp/nginx.pid; daemon off;'

~ $ docker inspect web01
[
    {
        "Id": "f9f7eb278e81d0c19f363e970616855d9c5aa9960e3e5ac2fa181592f0e9b12c",
        "Created": "2020-08-19T01:39:03.961208087Z",
        "Path": "/bin/sh",
        "Args": [],
        "State": {
            ..............
                }
    }
]

~ $ docker inspect web01 | grep IP
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
                    "IPAMConfig": null,
                    "IPAddress": "172.17.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,

~ $ curl 172.17.0.3
hello world!!


# publish
~ $ docker commit web01 web-base
sha256:b6290bdfc157161864f4fc2b2628903dfc315655eb040673186399b6a8ae49b0

~ $ docker run -p 80:80 -dt --name web02 web-base
d279a242a2de49701adb56166f6b8a3bb2551aad921c6b32c115449a68c7a39c

~ $ docker inspect web02 | grep IP
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
                    "IPAMConfig": null,
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,

~ $ curl 172.17.0.2
curl: (7) Failed to connect to 172.17.0.2 port 80: Connection refused

~ $ docker exec -dt web02 nginx -g 'pid /tmp/nginx.pid; daemon off;'

~ $ curl 172.17.0.2
hello world!!
~ $ curl 172.17.0.3
hello world!!
~ $ curl localhost
hello world!!


# browser: use local ip

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.