You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

69 lines
7.8 KiB

import { addBanner, addArticle, addTitle, addHeader, addParagraph, addSubHeader } from '/scripts/article.js';
import { addInset, addInsetList, addInsetCodeListing, addInsetBulletList } from '/scripts/inset.js';
import { addImageWithCaption, addButtonGroup } from '/scripts/visuals.js';
import { addSidebar} from '/scripts/sidebar.js';
import { addSyntax } from '/scripts/code.js';
import { menu } from '/scripts/web_dev_buttons.js';
import { global_menu } from '/scripts/grid_layout1.js';
import { local_menu } from '/scripts/programming.js';
const heading = document.querySelector(".heading");
const global = document.querySelector(".global_menu");
const local = document.querySelector(".local_menu");
const sidebar = document.querySelector(".sidebar");
const main = document.querySelector(".main_content");
heading.append(addParagraph("Carlos Nunez - LinkedIn Learning - December 2022"));
heading.append(addParagraph("USING DOCKER"));
global.append(global_menu());
local.append(local_menu("learningdocker"));
main.append(addHeader("The Docker Flow: Images to Containers"));
main.append(addParagraph("I'm going to take another diversion from the course here and look at using docker to set up a private search engine, which is why I was looking into it in the first place."));
main.append(addParagraph("In order to make the search engine accessible from anywhere, I created an account with Linode which allows me to set up a server in the cloud with a public ip address. For reference, you can sign up for an account at <a href='https://www.linode.com/'>linode.com</a>. As far as I can tell, you can create as many servers as you like at various price points. The cheapest costs $5 per month and that should be more than adequate for this purpose."));
main.append(addParagraph("You can ssh to the server from a command prompt but I prefer to do that from Ubuntu on Windows."));
main.append(addSyntax("ssh root@ip address"));
main.append(addParagraph("Before we install the search engine, we will cd into the folder we want to install it in."));
main.append(addParagraph("cd /usr/local"));
main.append(addParagraph("We can them install the search engine with the following."));
main.append(addSyntax("git clone https://github.com/searxng/searxng-docket-git"));
main.append(addParagraph("We can then cd to the directory where this is installed with"));
main.append(addParagraph("cd searxng-docker"));
main.append(addParagraph("and edit the .env file as follows:"));
main.append(addSyntax("SEARXNG_HOSTNAME=philgoogle.com"));
main.append(addSyntax("LETSENCRYPT_EMAIL=emubantam@gmail.com"));
main.append(addParagraph("For reference, we need to isntall both docker and docker compose on our server and we can do that with the commands"));
main.append(addSyntax("sudo apt install docker.io"));
main.append(addParagraph("and"));
main.append(addSyntax("sudo apt install docker-compose"));
main.append(addParagraph("we can generate an SSL key to provide greater security with the command"));
main.append(addSyntax("sed -i 's|ultrasecretkey|$(openssl rand -hex 32|g' searxng/settings.yml"));
main.append(addParagraph("This will generate a random 32 bit key and write it the settings.yml file in the searxng folder."));
main.append(addParagraph("Next, we can set up our docker container with the command"));
main.append(addSyntax("sudo docker-compose up -d"));
main.append(addParagraph("The d option tells the system to run the docker image as a daemon."));
main.append(addParagraph("If we want to check what docker containers are running, we can do that with the command"));
main.append(addSyntax("sudo docker ps"));
main.append(addParagraph("Getting back to the course, it is worth considering what exactly a docker image is. Essentially, it is just enough of the operating system for whatever it is you want to do. In other words, it isn't a complete OS so it is not what you would consider to be a VM. This makes it very effiecient and you can have a lot of them running within a physical or virtual machine."));
main.append(addParagraph("If you want to check out what images are currently running, you can do that with the command"));
main.append(addSyntax("docker images"));
main.append(addParagraph("The output from this is shown in figure 3."));
main.append(addImageWithCaption("images/docker_images.png", "Figure 3 - the outpt we get from the command 'docker images'"));
main.append(addParagraph("I had mentioned previously that we could user docker ps to see what docker containers are running and for comparsion, the output from running this command is shown in figure 4."));
main.append(addImageWithCaption("images/docker_ps.png", "Figure 4 - the outpt we get from the command 'docker ps'"));
main.append(addParagraph("There are some similarities in the images shown in figures 3 and 4. From docker ps, we are getting an image name which combines the repository (where the image came from) and the tag (which is essentially the version). These are showm separately under docker images."));
main.append(addParagraph("Both show an id which is either for the container or the image and roughly the time when it was created."));
main.append(addParagraph("We also have a size under docker images which we don't see with docker ps. Conversely, with docker ps, we see a command, a port and a name."));
main.append(addParagraph("In any docker command, if you need to refer to an image, you can do that using its name which id the respository and tag separated by a colon. Note that the docker ps command displays the image name in this format. ALternatively, you can reference the image with the image id."));
main.append(addParagraph("The docker run command takes an image and converts it to a running container with some processes running and these processes are doing the work the container was created to do."));
main.append(addParagraph("A typical docker run command might look like this."));
main.append(addSyntax("docker run -t ubuntu bash"));
main.append(addParagraph("The -it option specifies that we want to run the container with and adding bash at the end means that it will open a shell for you. In case you are wondering what this looks like, you may know that in Linux, if you use the su command with a hyphen, as in"));
main.append(addSyntax("sudo -"));
main.append("this does something similar. It will switch to a different user account and start a new shell process so may not immediately see a difference but you will be working in a shell belonging to that user. To make this a little clearer, I hope, I am accessing my Linode server using a Ubuntu shell in Windows. If I execute the command as shown above, a new shell is created as shown in the image in figure 5.")
main.append(addImageWithCaption("images/docker_run.png", "Figuer 5 - demonstrating the docker run command."));
main.append(addParagraph("So, here, we are connecting to a server that already has docker running and we are using the run command as show above. As a reminder, that is"));
main.append(addSyntax("docker run -t ubuntu bash"));
main.append(addParagraph("You might notice that the prompt then changes indicating that a new shell process has been initiated. I then tried to run the docket images command and got a command not found error and this is, of course because the new Ubuntu shell does not have access to docker. We can exit this shell with control+D (note the original prompt is restored) and we can then run docker images and we can see that the Ubuntu shell is listed there."));
main.append(addParagraph("This may be jumping ahead a little, but it is interesting to note that it is not listed inder containers, which we will see if we excuted the docker ps command which suggests that images and containers are not (as I had thought, just different ways of describing the same thing. Hopefully, that will become clear later!"));
addSidebar("programming");