How to!

Dockerfile

FROM alpine:3.4

RUN apk update

# nginx
RUN apk add nginx
RUN mkdir -p /run/nginx

# start up
ENTRYPOINT nginx -g 'daemon off;'

Bygg

$ sudo docker build --tag nginx .
Sending build context to Docker daemon  5.12 kB
Step 1 : FROM alpine:3.4
 ---> baa5d63471ea
Step 2 : RUN apk update
 ---> Using cache
 ---> 2e5619c9caa7
Step 3 : RUN apk add nginx
 ---> Using cache
 ---> 95a4848b546b
Step 4 : RUN mkdir -p /run/nginx
 ---> Using cache
 ---> ccd52cd2286b
Step 5 : ENTRYPOINT nginx -g 'daemon off;'
 ---> Running in 79399fc4d9ce
 ---> b88fed45c51a
Removing intermediate container 79399fc4d9ce
Successfully built b88fed45c51a

Run

$ sudo docker run --detach --name nginx-demo nginx
8b7edd53dba5e178d92365243c9a1f44ade31af0fa1afb23a608533195b57409

PS og curl

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
8b7edd53dba5        nginx               "/bin/sh -c 'nginx -g"   4 seconds ago       Up 4 seconds                            nginx-demo

# Vi trenger IP for å curl
$ sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' nginx-demo
172.17.0.3

$ curl 172.17.0.3
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

La oss snakke om kontainere

By Kyrre Havik

La oss snakke om kontainere

  • 89