How to temporarily fix the message “TERM environment variable not set” while working with a Docker container

Sometimes at least these days with the current version of Docker you may stumble upon the message “TERM environment variable not set”.

This happened to me while being inside a container with “docker exec -ti”.

clear, top, etc. were not working and complaining about the not set variable.

If you execute this while inside the container:

export TERM=xterm

or

export TERM=${TERM:-dumb}

the warnings will stop and you can have the real thing.

Owncloud: How to change the admin password from the command line.

I’ve been playing with Owncloud in a Docker container today and something was not set right. The admin password was not the default one. So my options were to delete the sqlite db file or run some password generating commands and queries to update the password.

The first thing is to generate a new sha1 password:

echo -n "password" | sha1sum

Use the result from the command above as the new password.

The second thing is to open the sqlite database with the sqlite3 command and update the admin’s password:

cd /var/www/owncloud/data
sqlite3 owncloud.db
update oc_users set password = "newsha1password" where uid = "admin";
.quit

Now you can login normally with admin/newpassword and from there you can set up all of the rest.

The sources I used for this article: here and here.

Docker image with Jenkins CI and full PHP configuration and tools

See it in action here.

Get the source from Github here.

This Docker image follows the http://jenkins-php.org/ configuration for installing Jenkins CI and the PHP testing tools.

It uses Ubuntu 14.04 LTS image.

The PHP 5.5 PPA by Ondřej Surý is used for the latest version of PHP and its extensions.

For Jenkins the Debian deb repo is used.

The deb mirrors.ubuntu.com/mirrors.txt is used for faster local updating/downloading of the apt packages.

DEBIAN_FRONTEND=noninteractive and apt-get -qq are used for automatic silent installs.

date.timezone=Europe/Sofia and ;disable_functions= are set in php.ini

After Jenkins is installed and needs its first update there is a wait of 60 seconds until the update script is called.

The Jenkins server is first updated before installing the plugins.

Currently these plugins are installed: checkstyle cloverphp crap4j dry htmlpublisher jdepend plot pmd violations xunit.

And these PHP testing tools are installed globally through Composer: phpunit/phpunit, squizlabs/php_codesniffer, phploc/phploc, pdepend/pdepend, phpmd/phpmd, sebastian/phpcpd, theseer/phpdox.

Composer installs the tools in /home/jenkins/.composer and makes all of them available globally in /usr/local/bin/.

Composer is set to use git to fetch the dependencies to avoid the GitHub API rate limits.

Port 8080 is exposed and available. This is the default Jenkins’ port.

The default CMD in the image is: “sh /run_all.sh”

Install

First download the image:

docker pull iliyan/jenkins-ci-php:1.0.0

And run it:

Locally:

docker run -d --name jenkins -p localhost:8080:8080 iliyan/jenkins-ci-php:1.0.0

Visible from outside on a hosting server:

docker run -d --name jenkins -p VISIBLESERVERPORT:8080 iliyan/jenkins-ci-php:1.0.0

Alternative usage of the PHP testing tools:

You can download all of the tools from your project’s composer.json file adding them for example in the dev secion like I did here and here.

Docker container with broken Mysql database. Lesson learned. Backup often. Backup your DB or at least the container.

I’ve been updating lxc-docker every time a new version is suggested by my Linux OS. While the apt-get install lxc-docker was working it stops and starts again with the new Docker version. Usually nothing happens with the containers being forced stop and started that way but today I’ve had a broken Mysql DB for this WordPress installation and couldn’t restore it from its data directory no matter what I’ve tried. Because I didn’t want to loose more time I decided I can restore previous commits to the same image that container is running from.

I’ve found the docker history imagename command and tried it. I’ve added a couple of commits to this image and I’ve had a couple of lines with the history commands. I’ve picked the commit before the broken state and ran the wordpress container the same way I am running it with the :latest tag but this time used the commit ID. It ran well and I’ve made a commit from it to its image. Stopped and removed the wordpress container and ran it with the usual command using the latest imagename command this time and now it’s running well.

Now I know that when I am going to stop the images and update the Docker executable I must backup the databases, files and commit the latest state of the containers (not much by the rules because the container should be able to be rebuilt at any time keeping the data outside the container).

Just started learning PhalconPHP

http://phalconphp.com

I just started learning it by reading its online documentation. I will definitely have to find a book about it and there is at least one out there and also I have to pass through all the examples like 10 times until I sit and make something with it. The installation of course is the easiest part, even inside a Vagrant box or Docker.

Preview of Docker Benchmarking at Flux7 | Flux 7

Preview of Docker Benchmarking at Flux7 | Flux 7.

The way I see it, Docker is in a position similar to AWS: revolutionary; easy to get started on; but to enjoy many of the benefits, you need to have someone guide you and ramp you up to really unlock the benefits or use the technology.

How to install and configure GitLab inside a Docker container: The Ready-Made Edition

Update: Please check the best Gitlab Docker container that I’ve found already a long time ago: https://github.com/sameersbn/docker-gitlab
Everything you need to set it up is on the page. I am using it and it does exactly what you expect it to do. You should read only the updates of this post. The alternative image from the original post is too old and we don’t need it anymore. Enjoy!

Update 2: And don’t forget to secure it with free HTTPS!

Update3: To help you start faster I’ve created an example configuration with the Docker image from the Update 1 link:

docker run –name=gitlab -d \
-e ‘DB_TYPE=mysql’ \
-e “DB_HOST=172.17.42.1”
-e “DB_NAME=gitlabhq_production”
-e “DB_USER=gitlab” -e “DB_PASS=yourpass” \
–link redis:redisio \
-v /home/yourusername/gitlab/data:/home/git/data \
-e “GITLAB_HOST=gitlab.yourdomain.com” \
-e [email protected]
-e [email protected] \
-e [email protected] -e “SMTP_PASS=yoursmtppass” \
-e “GITLAB_BACKUPS=daily” \
-e “GITLAB_SHELL_SSH_PORT=2222” \
-e “GITLAB_HTTPS=true” \
-e “GOOGLE_ANALYTICS_ID=UA-xxxxxx-xx” \
-p 172.17.42.1:8080:80 -p 2222:22 \
sameersbn/gitlab:7.8.1

The IP used is the internal Docker network address. I assume that you want to put Gitlab behind a reverse proxy on the same host. You may change it to another internal IP for the DB connection option and also remove it from the port forwarding to have the web port(8080) visible from the outside on your domain.

This configuration needs a `redis` named container running and the Gitlab container will link to it. Also the HTTPS is enabled, google tracking added and at the end port 2222(used by git+ssh) is open for your domain.

You may decide to dedicate a host for Gitlab only. Then you will set it to use port 22 for SSH and 80/443 for web. Check Update 2 above to see a sample nginx configuration for HTTPS.


The original post:

For this we are going to use a ready-made configuration for building the image and easy configuring it from https://github.com/crashsystems/gitlab-docker

We will follow these procedures: https://github.com/crashsystems/gitlab-docker/tree/master with some additions for our specific example.

You have a couple of things to do. First download the configuration and use the Dockerfile inside to build the base image:

git clone https://github.com/crashsystems/gitlab-docker.git
cd gitlab-docker
docker build -t crashsystems/gitlab-docker .

Wait until it’s done and now it’s time to configure hostnames and passwords using the .yml and .sh files that came with the Dockerfile from the git clone:

nano config/gitlab.yml

Change the hostname with something like: mygit.yourdomain.com. I will also change the standard port number 22 of the gitlab shell to one non standard and available on the host: 22222. Later we’ll use this port in docker run to redirect incoming requests for gitlab from the host.

Next is the database password for the gitlab MySQL user:

nano config/database.yml

change:

password: "secure password"

with a good one.

Finally, change the server name in the nginx config file:

nano config/nginx

It should be mygit.yourdomain.com as the gitlab.yml configuration above.

Now you are going to start the container:

docker run -d -v /your/path/to/gitlab-docker:/srv/gitlab --name gitlab -p 172.17.42.1:82:80 -p 22222:22 crashsystems/gitlab-docker

This will use your local host’s directory for storing the gitlab files and the gitlab container will respond on ports 22222 for ssh git operations and the internal 82 which we are going to use with a proxy from a nginx server already running on port 80 on the host:

nano /etc/nano/sites-enabled/yourdomain.com
server {
    server_name mygit.yourdomain.com;
    location / {
        #you may like to have a basic auth on top of the gitlab's one:
        #auth_basic "Restricted";
        #auth_basic_user_file /your/path/to/.htpasswd;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_read_timeout 300;
        proxy_pass http://172.17.42.1:82;
    }
}

Restart/reload nginx’s configuration:

/etc/init.d/nginx reload

Now go to mygit.yourdomain.com and the login page should be shown. Use these defaults:

user: [email protected]
pass: 5iveL!fe

Create a new project and you’ll see the url to the gitlab repo you’re going to use from now on is like:

git remote add origin ssh:[email protected]:22222/root/test-project.git

Add one or more public ssh keys in gitlab’s interface and start using it! 🙂