官术网_书友最值得收藏!

  • Deployment with Docker
  • Srdjan Grubor
  • 361字
  • 2021-07-02 23:22:12

Building and running

Now that we went over the whole build configuration, we can create our image and see what we just made:

$ docker build -t web_server .

Sending build context to Docker daemon 17.41kB
Step 1/6 : FROM nginx:latest
---> b8efb18f159b
Step 2/6 : RUN apt-get update -q && apt-get dist-upgrade -yq
---> Running in 5cd9ae3712da
Get:1 http://nginx.org/packages/mainline/debian stretch InRelease [2854 B]
Get:2 http://security.debian.org stretch/updates InRelease [62.9 kB]
Get:3 http://nginx.org/packages/mainline/debian stretch/nginx amd64 Packages [11.1 kB]
Get:5 http://security.debian.org stretch/updates/main amd64 Packages [156 kB]
Ign:4 http://cdn-fastly.deb.debian.org/debian stretch InRelease
Get:6 http://cdn-fastly.deb.debian.org/debian stretch-updates InRelease [88.5 kB]
Get:7 http://cdn-fastly.deb.debian.org/debian stretch Release [118 kB]
Get:8 http://cdn-fastly.deb.debian.org/debian stretch Release.gpg [2373 B]
Get:9 http://cdn-fastly.deb.debian.org/debian stretch/main amd64 Packages [9497 kB]
Fetched 9939 kB in 40s (246 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
---> 4bbd446af380
Removing intermediate container 5cd9ae3712da
Step 3/6 : RUN rm /etc/nginx/conf.d/default.conf
---> Running in 39ad3da8979a
---> 7678bc9abdf2
Removing intermediate container 39ad3da8979a
Step 4/6 : RUN mkdir -p /srv/www/html && chown nginx:nginx /srv/www/html
---> Running in e6e50483e207
---> 5565de1d2ec8
Removing intermediate container e6e50483e207
Step 5/6 : COPY nginx_main_site.conf /etc/nginx/conf.d/
---> 624833d750f9
Removing intermediate container a2591854ff1a
Step 6/6 : COPY test.txt /srv/www/html/
---> 59668a8f45dd
Removing intermediate container f96dccae7b5b
Successfully built 59668a8f45dd
Successfully tagged web_server:latest

Seems like the container build is just fine; let's run it:

$ docker run -d \
-p 8080:80 \
--rm \
web_server

bc457d0c2fb0b5706b4ca51b37ca2c7b8cdecefa2e5ba95123aee4458e472377

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bc457d0c2fb0 web_server "nginx -g 'daemon ..." 30 seconds ago Up 29 seconds 0.0.0.0:8080->80/tcp goofy_barti

So far, so good, as it seems to be running fine. Now we will access the container with our browser at http://localhost:8080.

As we were hoping, our server is working and showing us the content of /srv/www/html, but let's click on test.txt to make sure it is working too:

Great, it looks like our plan worked and we have created a high-performance static website hosting server container! Sure, there are many other things we can add to this, but our main goal of extending a sample image to do something useful is a success!

主站蜘蛛池模板: 蓬溪县| 仪陇县| 中山市| 澳门| 合阳县| 虹口区| 溆浦县| 金山区| 蓝田县| 桦南县| 延川县| 科技| 灌南县| 兰州市| 嘉善县| 黄平县| 和硕县| 珲春市| 安吉县| 利津县| 惠安县| 赤峰市| 泗水县| 景东| 德化县| 手游| 南和县| 南投市| 济阳县| 乌拉特前旗| 周口市| 公安县| 拜泉县| 白朗县| 永顺县| 进贤县| 隆昌县| 龙井市| 伊宁县| 鞍山市| 罗江县|