Comments on How to create Docker Images with a Dockerfile on Ubuntu 16.04 LTS
In this tutorial, I will show you how to create your own docker image with a dockerfile. A Dockerfile is a script that contains collections of commands and instructions that will be automatically executed in sequence in the docker environment for building a new docker images. As example, we will create a Nginx Web server with PHP-FPM.
11 Comment(s)
Comments
is there an alternative then doing vi on docker container ? I mean copy-paste of many configurations is troublesome job.
In your dockerfile you have multiple volumes in the [VOLUME] section, doesn't this mean that you should be referencing this in the run command when you first run off of your built image. Does there need to be a -v for each of the items in [VOLUME] in the run command?
docker run -d -v /webroot:/var/www/html -p 80:80 --name hakase nginx_image
Something like this: docker run -d -v /webroot:/var/www/html -v /ssl/certs:/etc/nginx/certs -v /etc/sites/etc:/etc/nginx/sites-enabled -p 80:80 -p 443:443 --name hakase nginx_image
# Volume configuration
VOLUME ["/etc/nginx/sites-enabled", "/etc/nginx/certs", "/etc/nginx/conf.d", "/var/log/nginx", "/var/www/html"]For one want to run NGINX use TCP/IP 127.0.0.1:9000:
- Update default nginx vhost: change line with fastcgi_pass to fastcgi_pass 127.0.0.1:9000;- In Dockerfile update these line:
+ Add ENV variable refer to fpm pool.d/www.conf:
ENV fpm_pool_www /etc/php/7.0/fpm/pool.d/www.conf
+ Then use sed command to edit www.conf:
RUN sed -i 's/listen = \/run\/php\/php7.0-fpm.sock/listen = 127.0.0.1:9000/g' ${fpm_pool_www}
I followed all the commands using a mac and tweaked where necessary. I was able to create the image and to run an instance. I pointed the host port to 8080 but I am getting an empty response when I visit http://host_ip:8080. This is my docker command: docker run -d -v ~/Sites/webroot:/var/www/html -p 8080:80 --name vhr_opencart nginx_image
i hope this tutorial is just a proof of concept , because otherwise is far from optimal from a best practices point of view
and what would be optimal have any examples
curl 192.168.1.250curl -I 192.168.1.250
If I follow your instruction verbatim. The two above commands do not work.
Do you have to install nginx on the system?
There is something missing with your instructions.
do that:docker ps
then that:docker inspect <container ID>
and look for IPAddress.
That description is missing. I have found it elsewhere. Cheers.
Thanks a lot for sharing step by step and explained docuement.
Reagards
Mahender
Nicely done article, What if I want to create multiple server blocks? How would that look in this configuration?
Thanks,
Thank you for this tutorial. It was very helpful