Dockerfile source for nginx docker image.
This source repo was originally copied from: https://github.com/nginxinc/docker-nginx
This is not an official Google product.
This image contains an installation Nginx
For more information, see the Official Image Marketplace Page.
Pull command (first install gcloud):
gcloud auth configure-docker && docker -- pull marketplace.gcr.io/google/nginx1Dockerfile for this image can be found here.
Consult marketplace container documentation for additional information about setting up your Kubernetes environment.
Copy the following content to pod.yaml file, and run kubectl create -f pod.yaml.
apiVersion: v1
kind: Pod
metadata:
name: some-nginx
labels:
name: some-nginx
spec:
containers:
- image: marketplace.gcr.io/google/nginx1
name: nginxRun the following to expose the ports. Depending on your cluster setup, this might expose your service to the Internet with an external IP address. For more information, consult Kubernetes documentation.
kubectl expose pod some-nginx --name some-nginx-80 \
--type LoadBalancer --port 80 --protocol TCP
kubectl expose pod some-nginx --name some-nginx-443 \
--type LoadBalancer --port 443 --protocol TCPFor information about how to retain your data across restarts, see Use a persistent data volume.
For information about how to configure your web server, see Web server configuration.
To preserve your web server data when the container restarts, put the web content directory on a persistent volume.
By default, /usr/share/nginx/html directory on the container houses all the web content files.
Copy the following content to pod.yaml file, and run kubectl create -f pod.yaml.
apiVersion: v1
kind: Pod
metadata:
name: some-nginx
labels:
name: some-nginx
spec:
containers:
- image: marketplace.gcr.io/google/nginx1
name: nginx
volumeMounts:
- name: webcontent
mountPath: /usr/share/nginx/html
volumes:
- name: webcontent
persistentVolumeClaim:
claimName: webcontent
---
# Request a persistent volume from the cluster using a Persistent Volume Claim.
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: webcontent
annotations:
volume.alpha.kubernetes.io/storage-class: default
spec:
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 5GiRun the following to expose the ports. Depending on your cluster setup, this might expose your service to the Internet with an external IP address. For more information, consult Kubernetes documentation.
kubectl expose pod some-nginx --name some-nginx-80 \
--type LoadBalancer --port 80 --protocol TCP
kubectl expose pod some-nginx --name some-nginx-443 \
--type LoadBalancer --port 443 --protocol TCPThe web server configuration should also be on a persistent volume. For more information, see Web server configuration.
Nginx configuration file is at /etc/nginx/nginx.conf.
kubectl exec some-nginx -- cat /etc/nginx/nginx.confThe default nginx.conf includes all configuration files under /etc/nginx/conf.d directory. If you have a /path/to/your/site.conf file locally, you can start the server as followed to mount it under conf.d directory.
Create the following configmap:
kubectl create configmap site-conf \
--from-file=/path/to/your/site.confCopy the following content to pod.yaml file, and run kubectl create -f pod.yaml.
apiVersion: v1
kind: Pod
metadata:
name: some-nginx
labels:
name: some-nginx
spec:
containers:
- image: marketplace.gcr.io/google/nginx1
name: nginx
volumeMounts:
- name: site-conf
mountPath: /etc/nginx/conf.d
volumes:
- name: site-conf
configMap:
name: site-confRun the following to expose the ports. Depending on your cluster setup, this might expose your service to the Internet with an external IP address. For more information, consult Kubernetes documentation.
kubectl expose pod some-nginx --name some-nginx-80 \
--type LoadBalancer --port 80 --protocol TCP
kubectl expose pod some-nginx --name some-nginx-443 \
--type LoadBalancer --port 443 --protocol TCPWe can move the web content to the container with the commands below, assuming /usr/share/nginx/html is where nginx has been configured to read from.
Create the directory if it does not exist yet.
kubectl exec some-nginx -- mkdir -p /usr/share/nginx/htmlCopy the index.html file.
kubectl cp /path/to/your/index.html some-nginx:/usr/share/nginx/html/index.htmlFollow instructions in Testing the web server, you should get back the content of your index.html.
Attach to the webserver.
kubectl exec -it some-nginx -- bashInstall curl.
apt-get update && apt-get install -y curl
We can now use curl to see if the webserver returns content.
curl http://localhost
Consult marketplace container documentation for additional information about setting up your Docker environment.
Use the following content for the docker-compose.yml file, then run docker-compose up.
version: '2'
services:
nginx:
container_name: some-nginx
image: marketplace.gcr.io/google/nginx1
ports:
- '80:80'
- '443:443'Or you can use docker run directly:
docker run \
--name some-nginx \
-p 80:80 \
-p 443:443 \
-d \
marketplace.gcr.io/google/nginx1For information about how to retain your data across restarts, see Use a persistent data volume.
For information about how to configure your web server, see Web server configuration.
To preserve your web server data when the container restarts, put the web content directory on a persistent volume.
By default, /usr/share/nginx/html directory on the container houses all the web content files.
Also assume that /my/persistent/dir/www is the persistent directory on the host.
Use the following content for the docker-compose.yml file, then run docker-compose up.
version: '2'
services:
nginx:
container_name: some-nginx
image: marketplace.gcr.io/google/nginx1
ports:
- '80:80'
- '443:443'
volumes:
- /my/persistent/dir/www:/usr/share/nginx/htmlOr you can use docker run directly:
docker run \
--name some-nginx \
-p 80:80 \
-p 443:443 \
-v /my/persistent/dir/www:/usr/share/nginx/html \
-d \
marketplace.gcr.io/google/nginx1The web server configuration should also be on a persistent volume. For more information, see Web server configuration.
Nginx configuration file is at /etc/nginx/nginx.conf.
docker exec some-nginx cat /etc/nginx/nginx.confThe default nginx.conf includes all configuration files under /etc/nginx/conf.d directory. If you have a /path/to/your/site.conf file locally, you can start the server as followed to mount it under conf.d directory.
Use the following content for the docker-compose.yml file, then run docker-compose up.
version: '2'
services:
nginx:
container_name: some-nginx
image: marketplace.gcr.io/google/nginx1
ports:
- '80:80'
- '443:443'
volumes:
- /path/to/your/site.conf:/etc/nginx/conf.d/site.confOr you can use docker run directly:
docker run \
--name some-nginx \
-p 80:80 \
-p 443:443 \
-v /path/to/your/site.conf:/etc/nginx/conf.d/site.conf \
-d \
marketplace.gcr.io/google/nginx1We can move the web content to the container with the commands below, assuming /usr/share/nginx/html is where nginx has been configured to read from.
Create the directory if it does not exist yet.
docker exec some-nginx mkdir -p /usr/share/nginx/htmlCopy the index.html file.
docker cp /path/to/your/index.html some-nginx:/usr/share/nginx/html/index.htmlFollow instructions in Testing the web server, you should get back the content of your index.html.
Attach to the webserver.
docker exec -it some-nginx bashInstall curl.
apt-get update && apt-get install -y curl
We can now use curl to see if the webserver returns content.
curl http://localhost
These are the ports exposed by the container image.
| Port | Description |
|---|---|
| TCP 80 | Nginx http default port |
| TCP 443 | Nginx https secure connection over SSL |
| TCP 9113 | Prometheus metrics exporter |
These are the filesystem paths used by the container image.
| Path | Description |
|---|---|
| /etc/nginx | Contains nginx configuration files, including nginx.conf. The default nginx.conf include all .conf files under the subdirectory conf.d. |