Sample Dockerfile 2

  • Shows how we can extend/change an existing official image from Docker Hub

    • extends the official nginx and serve our own index.html
  • We don't need to specify EXPOSE or CMD because they're in nginx:latest from which we build

  • We DON'T inherit ENV's from our upstream image

Dockerfile

FROM nginx:latest
# highly recommend you always pin versions for anything beyond dev/learn

WORKDIR /usr/share/nginx/html
# change working directory to root of nginx webhost
# using WORKDIR is prefered to using 'RUN cd /some/path'

COPY index.html index.html

index.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">

  <title>Your 2nd Dockerfile worked!</title>

</head>

<body>
  <h1>You just successfully ran a container with a custom file copied into the image at build time!</h1>
</body>
</html>

Output of 'docker image build'

~> docker image build -t nginx-with-html .
Sending build context to Docker daemon  3.072kB
Step 1/3 : FROM nginx:latest
 ---> da5939581ac8
Step 2/3 : WORKDIR /usr/share/nginx/html
 ---> 6b444f772ebb
Removing intermediate container d4a6e7e9b5a4
Step 3/3 : COPY index.html index.html
 ---> dcbe42137006
Removing intermediate container 458231887d7a
Successfully built dcbe42137006
Successfully tagged nginx-with-html:latest

Create/run container from our image

~> docker container run -d -p 80:80 --rm nginx-with-html
~> curl localhost
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">

  <title>Your 2nd Dockerfile worked!</title>

</head>

<body>
  <h1>You just successfully ran a container with a custom file copied into the image at build time!</h1>
</body>
</html>

results matching ""

    No results matching ""