Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Tutorials
Docker Tutorial
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Jepzter" data-source="post: 438005" data-attributes="member: 81100"><p style="text-align: center"><strong><span style="font-size: 22px">Welcome to the Docker Tutorial!</span></strong></p> <p style="text-align: center"><span style="font-size: 22px"><strong><img src="https://www.docker.com/sites/default/files/social/docker_facebook_share.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /> </strong></span></p> <p style="text-align: center"><strong></strong></p> <p style="text-align: center"><strong><em><u>These are the items we're looking at in this tutorial</u></em></strong></p> <ol> <li data-xf-list-type="ol"><strong>What is docker?</strong></li> <li data-xf-list-type="ol"><strong>How to install docker</strong></li> <li data-xf-list-type="ol"><strong>Running your first docker image in your container</strong></li> <li data-xf-list-type="ol"><strong>Building your own docker image</strong></li> </ol> <ol> <li data-xf-list-type="ol">Docker is a great way to have your services between multiple running just like the production environment would. You don't have to do anything just because you are on a Linux machine your friend is on a Windows and the production environment is on a Linux kernel of some sort. Docker helps you solve this by running built images in a container environment, we can compare it to a more lightweight way of Hyper-V / Virtualbox, even though it's completely different. This makes sure that there will be no different between the environments and therefor you don't have to worry about your application running on different environments, docker makes sure it works all the time. <br /> <br /> What's also great about Docker is how simple it is, you write a simpel-syntax configuration file with the parts that your docker container should contain, lets say ours will contain <strong>NGINX</strong>. To create this you have to write a config file with 4 lines to start the simplest NGINX webserver. <br /> <br /> Loadbalancing can also be done with docker, and by loadbalancing Im not talking about the network load, only about the metrics of CPU/Memory/Other IO. What you can do is specify what exposed ports your application should have and start multiple docker containers in less than 10 seconds to balance the load, this can be automatically done when you attach Kubernetes/Minikube, which is another tutorial.</li> <li data-xf-list-type="ol">Docker can be downloaded from <a href="https://www.docker.com/get-started" target="_blank">here</a>, and the installation should just be a walk in the park. When you're done installing head over to <a href="https://hub.docker.com/" target="_blank">https://hub.docker.com/</a> and register an account, this is important if you want to push you're own images and save them in the cloud. <br /> <br /> Now we should start docker on our machine, go ahead and do that. When you are done you should open your terminal and run the command <br /> [CODE]docker[/CODE]<br /> And a list of commands for helping you out should be visible, then you know Docker is up and running. <br /> <br /> Let's go ahead and log in to the docker hub account you've made before on your local docker service. Run the following command:<br /> [CODE]docker login[/CODE]<br /> And fill in the prompted credentials. <br /> <strong><em>Congratulations, setup is completed!</em></strong></li> <li data-xf-list-type="ol">Now we are going to run our first docker image, I've pre-setup a simple website working with NGINX for this, and you can go ahead and pull this image from the docker hub, <a href="https://hub.docker.com/r/theovster/hello-devbest/" target="_blank">follow this link</a>. <br /> <br /> as you can see, docker has a command for fetching images, it's called a pull. Head back to your terminal again and run the following command<br /> [CODE]docker pull theovster/hello-devbest[/CODE]<br /> now you've got it, great lets run it!<br /> <br /> Run the following command in the terminal<br /> [CODE]docker run -p 8080:80 --name devbest theovster/hello-devbest[/CODE]<br /> Your application should be starting now. <br /> <br /> There is a interesting piece in this command, the flag <strong>-p </strong>this specifies the port that should be exposed. The syntax for that command follows <strong>exposing_port:service_target_port </strong>what this mean is that we expose the port 8080 for our docker container, but docker routes it to port 80, which NGINX runs on.<br /> <br /> You can kill this by either running<br /> [CODE]docker stop devbest[/CODE]<br /> or<br /> [CODE]docker kill devbest[/CODE]<br /> The prefered way is to use the stop command, as you then can start the image again by using<br /> [CODE]docker start devbest[/CODE]<br /> <br /> Congratulations, now head over to <a href="http://localhost:8080" target="_blank">http://localhost:8080</a> which the docker image is running on, you should see a very simple website.</li> <li data-xf-list-type="ol">Building your own docker image is very easy, in your code project you just have to add a file called <strong>Dockerfile</strong>, this file will contain the configuration for building your image.<br /> <br /> We are going to run on the same configuration as my <strong>theovster/hello-devbest </strong>image ran on, this is the configuration for it. <br /> [CODE]FROM nginx<br /> <br /> RUN mkdir /etc/nginx/logs && touch /etc/nginx/logs/static.log<br /> <br /> ADD ./nginx.conf /etc/nginx/conf.d/default.conf<br /> ADD /build /www<br /> [/CODE]<br /> The <strong>FROM nginx</strong> specifies that we will pull a docker image with nginx, <br /> The <strong>RUN mkdir /etc/nginx/logs && touch /etc/nginx/logs/static.log </strong>is neccessary for nginx to start, this will keep nginx logs, and wont create it itself.<br /> The <strong>ADD ./nginx.conf /etc/nginx/conf.d/default.conf </strong>will add the nginx.conf in your root path of your project, to the dockers configuration for running nginx.<br /> The <strong>ADD /build /www </strong>will copy your built website, to nginx webroot called<strong> www/</strong><br /> <br /> This is the only thing required for running your website on a NGINX server. Below is my <strong>nginx.conf </strong>which is a basic nginx configuration<br /> <br /> [CODE]server {<br /> root /www;<br /> <br /> location / {<br /> autoindex on;<br /> }<br /> <br /> # these settings are from https://github.com/h5bp/server-configs-nginx/blob/master/h5bp/location/expires.conf<br /> # feel free to change as much as you like<br /> # cache.appcache, your document html and data<br /> location ~* \.(?:manifest|appcache|html?|xml|json)$ {<br /> expires -1;<br /> access_log logs/static.log;<br /> }<br /> <br /> # Feed<br /> location ~* \.(?:rss|atom)$ {<br /> expires 1h;<br /> add_header Cache-Control "public";<br /> }<br /> <br /> # Media: images, icons, video, audio, HTC<br /> location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {<br /> expires 1M;<br /> access_log off;<br /> add_header Cache-Control "public";<br /> }<br /> <br /> # CSS and Javascript<br /> location ~* \.(?:css|js)$ {<br /> expires 1y;<br /> access_log off;<br /> add_header Cache-Control "public";<br /> }<br /> }<br /> [/CODE]<br /> <br /> <strong>Now let's build the image</strong><br /> Navigate your terminal to the root of your webproject where your <strong>Dockerfile </strong>is located, here we are going to build the image by running the following command<br /> [CODE]docker build -t dockerhubusername/my-project .[/CODE]<br /> Wait until it's finished building<br /> <br /> When it's built go ahead and run it by using the command I wrote about how to run a docker image. Now you should be able to navigate to your localhost, with chosen exposed port.<br /> <br /> <strong>Congratulations, it works! </strong><br /> You may now go ahead and deploy this docker image to all your servers, not setup needed, just run it!<br /> <br /> <strong>Pushing</strong><br /> Go to <a href="https://hub.docker.com" target="_blank">https://hub.docker.com </a>and create a repository for this image, with the same name as your image. On the docker hub webpage, hit create and select create repository.<br /> <br /> To push our image to docker hub, we can use the following command<br /> [CODE]docker push dockerhubusername/my-project:latest[/CODE]<br /> <br /> On your servers/production/other environments you can now do a docker pull and run the program like nothing ever happened!</li> </ol><p><strong>You've made it this far, great!</strong></p><p>I really hope that you found this tutorial good, please comment if you need more directions in how to do stuff. Remember, you can run docker way more advanced than this, but this is a great place to start. Place a comment below if you need any help on the road.</p><p></p><p style="text-align: center"><span style="font-size: 22px"></span></p> <p style="text-align: center"><span style="font-size: 22px"></span></p> <p style="text-align: center"></p></blockquote><p></p>
[QUOTE="Jepzter, post: 438005, member: 81100"] [CENTER][B][SIZE=6]Welcome to the Docker Tutorial![/SIZE][/B] [SIZE=6][B][IMG]https://www.docker.com/sites/default/files/social/docker_facebook_share.png[/IMG] [/B][/SIZE] [B] [I][U]These are the items we're looking at in this tutorial[/U][/I][/B][/CENTER] [LIST=1] [*][B]What is docker?[/B] [*][B]How to install docker[/B] [*][B]Running your first docker image in your container[/B] [*][B]Building your own docker image[/B] [/LIST] [LIST=1] [*]Docker is a great way to have your services between multiple running just like the production environment would. You don't have to do anything just because you are on a Linux machine your friend is on a Windows and the production environment is on a Linux kernel of some sort. Docker helps you solve this by running built images in a container environment, we can compare it to a more lightweight way of Hyper-V / Virtualbox, even though it's completely different. This makes sure that there will be no different between the environments and therefor you don't have to worry about your application running on different environments, docker makes sure it works all the time. What's also great about Docker is how simple it is, you write a simpel-syntax configuration file with the parts that your docker container should contain, lets say ours will contain [B]NGINX[/B]. To create this you have to write a config file with 4 lines to start the simplest NGINX webserver. Loadbalancing can also be done with docker, and by loadbalancing Im not talking about the network load, only about the metrics of CPU/Memory/Other IO. What you can do is specify what exposed ports your application should have and start multiple docker containers in less than 10 seconds to balance the load, this can be automatically done when you attach Kubernetes/Minikube, which is another tutorial. [*]Docker can be downloaded from [URL='https://www.docker.com/get-started']here[/URL], and the installation should just be a walk in the park. When you're done installing head over to [URL]https://hub.docker.com/[/URL] and register an account, this is important if you want to push you're own images and save them in the cloud. Now we should start docker on our machine, go ahead and do that. When you are done you should open your terminal and run the command [CODE]docker[/CODE] And a list of commands for helping you out should be visible, then you know Docker is up and running. Let's go ahead and log in to the docker hub account you've made before on your local docker service. Run the following command: [CODE]docker login[/CODE] And fill in the prompted credentials. [B][I]Congratulations, setup is completed![/I][/B] [*]Now we are going to run our first docker image, I've pre-setup a simple website working with NGINX for this, and you can go ahead and pull this image from the docker hub, [URL='https://hub.docker.com/r/theovster/hello-devbest/']follow this link[/URL]. as you can see, docker has a command for fetching images, it's called a pull. Head back to your terminal again and run the following command [CODE]docker pull theovster/hello-devbest[/CODE] now you've got it, great lets run it! Run the following command in the terminal [CODE]docker run -p 8080:80 --name devbest theovster/hello-devbest[/CODE] Your application should be starting now. There is a interesting piece in this command, the flag [B]-p [/B]this specifies the port that should be exposed. The syntax for that command follows [B]exposing_port:service_target_port [/B]what this mean is that we expose the port 8080 for our docker container, but docker routes it to port 80, which NGINX runs on. You can kill this by either running [CODE]docker stop devbest[/CODE] or [CODE]docker kill devbest[/CODE] The prefered way is to use the stop command, as you then can start the image again by using [CODE]docker start devbest[/CODE] Congratulations, now head over to [URL]http://localhost:8080[/URL] which the docker image is running on, you should see a very simple website. [*]Building your own docker image is very easy, in your code project you just have to add a file called [B]Dockerfile[/B], this file will contain the configuration for building your image. We are going to run on the same configuration as my [B]theovster/hello-devbest [/B]image ran on, this is the configuration for it. [CODE]FROM nginx RUN mkdir /etc/nginx/logs && touch /etc/nginx/logs/static.log ADD ./nginx.conf /etc/nginx/conf.d/default.conf ADD /build /www [/CODE] The [B]FROM nginx[/B] specifies that we will pull a docker image with nginx, The [B]RUN mkdir /etc/nginx/logs && touch /etc/nginx/logs/static.log [/B]is neccessary for nginx to start, this will keep nginx logs, and wont create it itself. The [B]ADD ./nginx.conf /etc/nginx/conf.d/default.conf [/B]will add the nginx.conf in your root path of your project, to the dockers configuration for running nginx. The [B]ADD /build /www [/B]will copy your built website, to nginx webroot called[B] www/[/B] This is the only thing required for running your website on a NGINX server. Below is my [B]nginx.conf [/B]which is a basic nginx configuration [CODE]server { root /www; location / { autoindex on; } # these settings are from https://github.com/h5bp/server-configs-nginx/blob/master/h5bp/location/expires.conf # feel free to change as much as you like # cache.appcache, your document html and data location ~* \.(?:manifest|appcache|html?|xml|json)$ { expires -1; access_log logs/static.log; } # Feed location ~* \.(?:rss|atom)$ { expires 1h; add_header Cache-Control "public"; } # Media: images, icons, video, audio, HTC location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { expires 1M; access_log off; add_header Cache-Control "public"; } # CSS and Javascript location ~* \.(?:css|js)$ { expires 1y; access_log off; add_header Cache-Control "public"; } } [/CODE] [B]Now let's build the image[/B] Navigate your terminal to the root of your webproject where your [B]Dockerfile [/B]is located, here we are going to build the image by running the following command [CODE]docker build -t dockerhubusername/my-project .[/CODE] Wait until it's finished building When it's built go ahead and run it by using the command I wrote about how to run a docker image. Now you should be able to navigate to your localhost, with chosen exposed port. [B]Congratulations, it works! [/B] You may now go ahead and deploy this docker image to all your servers, not setup needed, just run it! [B]Pushing[/B] Go to [URL='https://hub.docker.com']https://hub.docker.com [/URL]and create a repository for this image, with the same name as your image. On the docker hub webpage, hit create and select create repository. To push our image to docker hub, we can use the following command [CODE]docker push dockerhubusername/my-project:latest[/CODE] On your servers/production/other environments you can now do a docker pull and run the program like nothing ever happened! [/LIST] [B]You've made it this far, great![/B] I really hope that you found this tutorial good, please comment if you need more directions in how to do stuff. Remember, you can run docker way more advanced than this, but this is a great place to start. Place a comment below if you need any help on the road. [CENTER][SIZE=6] [/SIZE] [/CENTER] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Tutorials
Docker Tutorial
Top