I have prepared another Docker container for the Raspberry Pi 3, this time it’s a Nginx 1.13.1 with Alpine 3.6 ready to be used.
I have used as reference the official Dockerfile from Nginx and this Dockerfile from @smebberson, you can see the final result in my repository here, the size of this image is 25MB :), also you can get a copy as usual
With this image I have learned to use another of the Docker killers features, data volumes.
Data volumes are designed to persist data, independent of the container’s lifecycle. Docker therefore never automatically deletes volumes when you remove a container. You can add a data volume to a container using the
-v flag when you run a container. You could also use the
-v multiple times to mount multiple data volumes.
This means that we can have information outside the container and make it available using appropriate settings. As a software engineer this is fantastic, since you can have a whole development environment ready in a matter of minutes without having to install or to configure anything on your host.
As an example, see how straightforward it would be to use this container to serve browser games.
I’m going to use Survivor game and I’ll save it in the folder
Once you have downloaded all the games you want, it’s time to start a Nginx container just like this
-v ~/games:/var/www which tells docker that folder
~/games that we have recently created will point
/var/www folder inside the container.
Open a browser and type the IP of your Pi. In my case, the IP is 192.168.1.135 so then url is http://192.168.1.135
And it’s done, you will see in your browser a folder list with the games you’ve copied in folder
~/games. You can add more games if you like, the Nginx container will see all the changes immediately.
This Nginx image exposes also the folder
/etc/nginx/conf.d as a data volume, which means you can provide your custom server configuration (enable ssl, change error page location, etc.). The following command example will create a container and will mount as well nginx configuration folder.
~/custom-nginx-conf folder save your custom nginx server configuration.
Any question?, leave your comments below.