How do i create a basic nginx container using a dockerfile?
-
Create a Dockerfile using the uppercase "D"
FROM nginx:latest MAINTAINER Big Whale ADD ./index.html /usr/share/nginx/html/index.html EXPOSE 80
Create a sample index file to copy into the container
<h1>Welcome to hopesville</h1>
Build an image using the Dockerfile.
$ docker build . Sending build context to Docker daemon 64.99MB Step 1/4 : FROM nginx:latest ---> 7042885a156a Step 2/4 : MAINTAINER Big Whale ---> Using cache ---> 0ca41fc0d30b Step 3/4 : ADD ./index.html /usr/share/nginx/html/index.html ---> 1be4f5502158 Step 4/4 : EXPOSE 80 ---> Running in 03f42133f19d Removing intermediate container 03f42133f19d ---> f6de3106be76 Successfully built f6de3106be76
Check if container exists. Will not at this stage, you have only built the image.
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Check images. You can see the unlabelled images.
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> f6de3106be76 19 seconds ago 109MB
Create a container using the image you have built.
$ docker run -d -p 80:80 f6de3106be76 df1103871cb2b6a15b33aa9e24f0669e193fcfe52ef79d739ae90223c067ebf9
Check your index.html file was copied to the container.
$ curl http://localhost:80 <h1>Welcome to hopesville</h1>
© Lightnetics 2024