A docker webserver on CentOS 7

I will base my docker on the katacoda online tutorial. I will suppose you have the docker installed on a CentOS 7 system. We want to run a container that will be visible in our intranet, based on a nginx image. First we create a Dockerfile. Mine is looking like this:

Dockers/nginx ## > more Dockerfile 
FROM nginx:alpine
COPY static-html-directory /usr/share/nginx/html

Then we build an image, that we will call webserver-image:v1

Dockers/nginx ## > docker build -t webserver-image:v1 .
Sending build context to Docker daemon 4.608 kB
Step 1 : FROM nginx:alpine
Trying to pull repository docker.io/library/nginx ... 
alpine: Pulling from docker.io/library/nginx
ff3a5c916c92: Pull complete 
b4f3ef22ce5b: Pull complete 
8a6541d11dc3: Pull complete 
7e869e2dcf68: Pull complete 
Digest: sha256:48947591194ac5a9dce1e110f9198
 ---> 537527661905
Step 2 : COPY static-html-directory /usr/share/nginx/html
 ---> 933ca1ba4600
Removing intermediate container 53c4cc3ea6a3
Successfully built 933ca1ba4600

Now we will create a VLAN for the IP of the docker. On a console, I open the nm-connection-manager. I click on Add –> connection type VLAN, give it a name, choose an (online) working interface, give a VLAN id (a number) and a VLAN interface name. Then go to the IPv4 settings and give it an IP on the same subnet than the main machine. Basically, what I do is fill up that the same way the main interface +1 on the IP address (if the IP is free, of course). Let’s say our IP is 192.132.1.10, then the VLAN IP will be 192.132.1.11. Be aware of the netmask and route of your VLAN! You can test the VLAN is online by typing ifconfig -a, and ping 192.132.1.11. In my case, after a network restart, I’m now able to ping the address from another computer on my subnet.

Time to run the docker! We do so via one script, but in principle, there’s no difference if you simply copy and paste this on your command line:

docker run --name webserver \
 -v /var/www/html/:/usr/share/nginx/html/ \
 -d -p 192.132.1.11:80:80 \
 webserver-image:v1

A little bit of info, in case it is not obvious: –name is the docker name, -v is linking /var/www/html with the nginx html folder, -d is to run the docker in the backround, -p is to give the port (+ the IP address) and the last parameter is the image used for the docker. We are ready to point a browser to 192.132.1.11. You should see this:

nginx

Even from the remote client on the same intranet. Now, if you do chmod 755 on /var/www/html/, copy some index.html and stop and start the container again:

docker stop webserver
docker start webserver

you should see your index.html. We have our web server. Done!

Advertisements
Posted in bits, centos, linux, containers, docker, software, bash | Leave a comment

Create, run, destroy a docker no dockerfile on CentOS 7

Following up what I previously wrote here, I will now create an on-the-fly docker (??)  check what is there, and destroy it.  That is to say, without a dockerfile, but using a command. I use the instructions on the official httpd docker repository, and later I will polish the result.

/Docker/docker-container ## > docker run -dit --name \
my-apache-app -p 8080:80 \
-v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4
Unable to find image 'httpd:2.4' locally
Trying to pull repository docker.io/library/httpd ... 
2.4: Pulling from docker.io/library/httpd
4176fe04cefe: Pull complete 
d6c01cf91b98: Pull complete 
b7066921647a: Pull complete 
643378aaba88: Pull complete 
3c51f6dc6a3b: Pull complete 
4f25e420c4cc: Pull complete 
ccdbe37da15c: Pull complete 
Digest: sha256:6e61d60e4142ea44e8e69b22f1e739d1e
8e42001c03cedd6a5fd0b42463861f367407660d

My command is in bold. Be aware that, as usual, I cleaned up the output a little. To pull the docker (the technical word) takes in my case around 2 minutes. Let’s see what we got.

/Docker/docker-container ## > docker info
Containers: 1
 Running: 1
 Paused: 0
 Stopped: 1
Images: 9
... and a lot of more down here..

Right. It looks like we have a lot of images. Let’s list them.

/Docker/docker-container ## > docker images
REPOSITORY        TAG      IMAGE ID      CREATED        SIZE
docker.io/httpd   2.4      01154c38b473  6 days ago     177.4 MB
friendlyhello     latest   e87fd1aa91b7  2 weeks ago    148.3 MB
docker.io/python  2.7-slim 4fd30fc83117  10 weeks ago   138.5 MB

That’s a little misleading. I’m not sure the httpd image is my image, but let’s ignore it. Now I want to stop the container that is running, and delete it. We do stop, and info.

/Docker/docker-container ## > docker stop my-apache-app
my-apache-app
/Docker/docker-container ## > docker info
Containers: 1
 Running: 0
 Paused: 0
 Stopped: 1
Images: 9
...a lot of stuff here..

So that’s the way to stop a docker. How can I delete it? Again, we simply try a command (it is not delete) and check the result.

/Docker/docker-container ## > docker rm my-apache-app
my-apache-app
root@xleginon /Docker/docker-container ## > docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 9
...a lot of stuff here...

Mission accomplished. Docker deleted! Next step, to polish my docker definition.

Posted in bash, centos, containers, docker | Leave a comment

“Could not start D-bus. Can you call qdbus” error after KDE update CentOS 7

Scenario: The system needs to be updated. Before that, an AD user can log in no problem with kerberos credentials, the client is online and all the systems are up and running. Then I do yum update, no special tags attached. I have like 1049 packages to update or erase, but I go ahead. After I’m done, I reboot.

Symptoms: We have two desktops, GNOME and KDE, managed by the Gnome Desktop Manager (GDM) service. Another AD user can log in on both desktops (gnome and kde) but “this AD user” can log in only on Gnome, when trying on KDE, he gets a pop-up window with the message:

Could not connect to D-Bus. Can you call qdbus? 

You can only click OK. If you do so, the gdm login screen comes back. Trying again will bring you back to the same point.

Solution: As root, I call the qdbus. In fact, I restart it.

systemctl restart dbus.service

It doesn’t work. Following this ubuntu thread I go for having a look on the startkde script, placed on /usr/bin/. I edit my file, but it doesn’t look like any specific dbus is called (there’s nothing like qdbus=QT_SELECT=qt4 qdbus).  I managed to change the error message, but I didn’t fix the problem. What could this be?

I delete the /home/user/.kde folder for the user, but it is still not “regenerated”. I copy mine, that seems to work, with a similar result. Still I get the popup window. On this forum, they say it’s Qt-related. So I try updating Qt by typing this:

yum install PyQt4.x86_64 poppler-qt4.x86_64 poppler-qt4-devel.x86_64 PyQt4-devel.x86_64 avahi-qt4.x86_64 avahi-qt4-devel.x86_64

Unfortunately, still the user get the message. What could it be? Speaking with the user, it turns out he WAS installing his own Qt flavor.  On his bashrc I find the next:

export LD_LIBRARY_PATH=/home/user/Programs/qt/lib:\
/usr/lib64:$LD_LIBRARY_PATH

What if we comment this one? Shall we try that out? YESSSS. KDE is back. I understand that the system was “looking” for qt libraries in a certain order, and it was finding the “user” qt libraries instead of the “system” ones. And the user libraries were not capable of giving KDE what it wanted. That was, if I can say it like that, a good qdbus. Always rely on the public transport 😀 😀 😀

Posted in bits, centos, linux, yum, bash | Leave a comment

Removing a kernel with yum on CentOS 7

E molto facile e divertente. But I tend to forget the commands. First we list the existing kernels:

#> yum list kernel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.alpha-labs.net
 * centosplus: artfiles.org
 * epel: fr2.rpmfind.net
 * epel-testing: fr2.rpmfind.net
 * extras: centos.alpha-labs.net
 * updates: centos.bio.lmu.de
Installed Packages
kernel.x86_64   3.10.0-514.6.2.el7  @updates
kernel.x86_64   3.10.0-514.10.2.el7 @updates
kernel.x86_64   3.10.0-514.16.1.el7 @updates
kernel.x86_64   3.10.0-693.5.2.el7  @updates
kernel.x86_64   3.10.0-693.11.1.el7 @updates
Available Packages
kernel.x86_64 3.10.0-693.17.1.el7 updates

The installed kernel are in bold, the current kernel appears underlined. Then we write yum remove kernel-KERNEL-DETAIL. For example:

yum remove kernel-3.10.0-693.11.1.el7
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package kernel.x86_64 0:3.10.0-693.11.1.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=================================================
 Package Arch Version Repository Size
=================================================
Removing:
 kernel x86_64 3.10.0-693.11.1.el7 @updates 59 M

Transaction Summary
=================================================
Remove 1 Package

Installed size: 59 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Erasing : kernel-3.10.0-693.11.1.el7.x86_64 1/1 
 Verifying : kernel-3.10.0-693.11.1.el7.x86_64 1/1

Removed:
 kernel.x86_64 0:3.10.0-693.11.1.el7

Complete!

And done. Why am I doing it? Why should I clean up old kernels? Well, there’s the long and the short explanation. The long explanation I will not write, the short one, the system will not go to the next kernel unless there’s space on the boot partition for it. If your boot partition is small, you will not be able to have more than one kernel.

Maybe you have noticed also that I removed the newest kernel that was already installed (the 11.1). You need to do that from time to time, since new kernels come with new problems, and not all the things work on a new kernel out of the box.  In my case, the GPFS mounting was not working. Be aware and don’t forget testing everything!

Posted in bash, bits, centos, linux, yum | Leave a comment

Windows 10 enable ping and AD login

It is done similar to Windows 7. Just to save your time, in my case it didn’t work enabling some of the firewall rules:

 

  • Click Advanced Settings on the left.
  • From the left pane of the resulting window, click Inbound Rules.
  • In the right pane, find the rules titled File and Printer Sharing (Echo Request – ICMPv4-In).
  • Right-click each rule and choose Enable Rule.

 

as described in this post. I also tried in addition enabling the all the “File and Printer Sharing” rules, without luck. I write it in no just for the documentation.

I managed to get my ping by manually creating two new firewall rules, one for ICMPv4, the other for ICMPv6. You have a more detailed solution, with screen shots, on this how-to-geek post about. Why I didn’t do it using the command prompt, as suggested first on the top of the post? Let’s say, I’m reluctant to touch the command prompt in Windows. It took me quite some time to get my new Windows 10 license, and I don’t want to screw it up by mistyping on the command prompt. Or being more specific, I don’t want to screw up how my Windows 10 system speak up with my switch, since I don’t have control over it. I’m just a middle man here, with limited rights.

Now, I hook it up to our domain to allow Active Directory users to log in. And I can, but the user sign in in with a temporary profile. He or she will get this nasty message:

125754d1489936553-fix-youve-been-signed-temporary-profile-windows-10-a-we_cant_sign_into_your_account

You can fix that up following this solution. I’m not going to unless I’m asked to. I have a lot of users, and anyway the home folder is mounted if you log in, despite of the scary message. I will check if I can find an elegant way to avoid the message to pop up, once for all. Have a nice day…

Posted in bits, hardware, windows | Leave a comment

Checks (if) in bash

More bash notes. This information is present everywhere, but this one is useful for me. On this post, the “if”, or “if” used for checks. In a raw:

### check that INPUT folder is there
if [ ! -d "$INPUT" ]; then
   echo " INPUT folder missing or not readable" 
   exit 0;
fi
### check that file SCRIPT is there
if [ ! -f "$SCRIPT" ]; then
   echo " file SCRIPT missing or not readable" 
   exit 0;
fi
### check that VAR is not empty 
if [[ ! $VAR ]]; then
 echo " VAR missing or not readable" 
 exit 0;
fi

Now you can check “with if” if the file is there, if the directory is there and if your variable is empty. Otherwise the script ends (exit 0). You can see the power of these lines. Soon, if I can collect meaningful examples, I will write about flows (while, case…). And in the faaaar future, I will continue with similar post about the other programming languages…if only I could find my notes…

Posted in bash, bits, linux | Leave a comment

Change the output of echo in bash

And more bash. Why bash? Because of python. No, seriously, I use bash because I think it’s more basic than python. And at the end, the important thing is the algorithm. Once you have it, you can export it to another language. So if it runs in bash, it will run on another language.  Today I want to draw your attention to this stack overflow post about coloring the output of bash. You have two choices: coloring using ANSI codes:

RED='\033[0;31m'
NC='\033[0m' # No Color
printf "I ${RED}love${NC} Stack Overflow\n"
echo -e "I ${RED}love${NC} Stack Overflow"

Or using tput. Personally, I prefer tput. The same than above with tput reads:

tput setaf 1; echo "this is red text"; tput sgr0

There you have it. Miniclass finished. Ah, by the way, it seems there’s a better way to order files than the one I was using via ls. Just FYI. Enjoy your colors…

 

Posted in bash, C, centos, linux | Leave a comment