Tag: Update

How to Run and Update Docker Images and Containers

The following text shows the default workflow to run and update a Docker image based on the example of GitLab. But this should also work for other containers.

Docker Installation

First make sure that your local machine has Docker installed. I use Debian and for this, a detailed description is available in Dockers documentation. There are also instructions for CentOS, Ubuntu, Fedora and others.

You can check the installed Docker version:

docker version
Client: Docker Engine - Community
 Version:           20.10.11
 API version:       1.41
 ... 

Run a Docker Container

Let’s start with an environment variable that defines the path where all the Gitlab data is stored. This is outside of the Docker container which allows an easy update without loosing data. To define the variable $GITLAB_HOME, you can use:

export GITLAB_HOME="/srv/gitlab"

To run a Docker container, simply use the run command with your parameters. For GitLab, this might look like:

docker run --detach
  --hostname <host.example.com>
  --publish 443:443 --publish 80:80 --publish 2222:22
  --name gitlab
  --restart always  
  --volume $GITLAB_HOME/config:/etc/gitlab 
  --volume $GITLAB_HOME/logs:/var/log/gitlab
  --volume $GITLAB_HOME/data:/var/opt/gitlab
  gitlab/gitlab-ce:latest

You should use your own settings and replace <host.example.com> with your setup.

For the sake of completeness, you might also need a runner for GitLab. Let’s run this container as well:

docker run --detach 
  --name gitlab_runner
  --restart always 
  --network host 
  -v /run/docker.sock:/var/run/docker.sock 
  gitlab/gitlab-runner:latest

And this one needs to be registered in your GitLab instance:

docker exec -it gitlab_runner gitlab-runner register 
  --url https://<host.example.com>/
  --registration-token <registration_token>

More details about the configuration of the GitLab runner is descriped in this post.

Update a Docker Container to the Latest Version

Let’s check, which container are running by using:

docker ps

The output shows all your containers and their ids:

CONTAINER ID   IMAGE                         COMMAND                  CREATED       STATUS                 NAMES
02fe426970f1   gitlab/gitlab-ce:latest       "/assets/wrapper"        4 hours ago   Up 4 hours (healthy)   gitlab
5742e07f809b   gitlab/gitlab-runner:latest   "/usr/bin/dumb-init …"   4 days ago    Up 5 hours             gitlab_runner

We have to stop the container and remove the image. When you used a run command (for GitLab) as shown above, this should not affect the data as this is stored outside of the container.

docker stop 02fe426970f1
docker rm 02fe426970f1

To remove the associated image, you can use the docker rmi. For this, we need to find the id of this image by listing all images:

docker images
REPOSITORY         TAG      IMAGE ID       CREATED        SIZE
gitlab/gitlab-ce   latest   46cd6954564a   17 hours ago   2.36GB
mysql              5.7      c20987f18b13   2 weeks ago    448MB
cirrusci/flutter   2.8.1    98a87781f179   2 weeks ago    3.49GB

Now we can remove the image (in my case the gitlab-ce image):

docker rmi 46cd6954564a

The update of the image can be done by using pull. This will download the images (in this case the latest version) and stores it on your system:

docker pull gitlab/gitlab-ce:latest

After this, you can use the same run command as before to run a container with the updated image:

docker run --detach
  --hostname <host.example.com>
  --publish 443:443 --publish 80:80 --publish 2222:22
  --name gitlab
  --restart always  
  --volume $GITLAB_HOME/config:/etc/gitlab 
  --volume $GITLAB_HOME/logs:/var/log/gitlab
  --volume $GITLAB_HOME/data:/var/opt/gitlab
  gitlab/gitlab-ce:latest

A final check, shows the container is up and running:

docker ps
CONTAINER ID   IMAGE                         COMMAND                  CREATED        STATUS                 NAMES
f3dab1163c07   gitlab/gitlab-ce:latest       "/assets/wrapper"        2 minutes ago  Up 4 hours (healthy)   gitlab
5742e07f809b   gitlab/gitlab-runner:latest   "/usr/bin/dumb-init …"   4 days ago     Up 5 hours             gitlab_runner

Instead of automatically using the latest version of each image (e.g. gitlab/gitlab-ce:latest) you can also specify a version number like gitlab/gitlab-ce:14.5.2. This is helpful when you need to update a system in steps. Or if you need to follow a specific upgrade path, which is the case for GitLab.

Photo by Ian Taylor on Unsplash.

 

Note to Self Mail: create text templates for faster notes

Note To Self Mail

With the latest update 1.13.0 of Note to Self Mail, new text features have been introduced:

  • create static or dynamic text templates for faster input of contents
  • format the note text by using check lists or bullet lists

Use static or dynamic text templates

Text templates can be used for the input of repetitive contents. They can not only contain any static text, they can be extended with dynamic contents that are automatically replaced, when the template is inserted into the note. This includes: date, time, datetime or a unix timestamp. If you need additional contents, please let me know.

Text template selection

The first template uses Date as dynamic contents. Inserted into the note, it automatically adds the current date.

Text template with dynamic contents (date)

Text format: check and bullet lists

By default, a bullet list could already be used in previous versions of the app. Now, another toolbar action was added to insert also bullet lists. Both lists are made of pure text (without any html) to ensure a plain text note and therefore an easier parsing of the note in your inbox.

The app will handle the format of both of those lists automatically. Means, a new list item will automatically created with each new line.

Toolbar action for text format / check list in the note

Another helpful feature is the status change of check lists. Touching a checkbox will enable / disable the checkbox (see “Honey”).

Note text converted into a bullet list

Hope this helps to make your notes faster and more structured 🙂

You want to support this app?

Note to Self Mail - The fastest app to send your ideas into your inbox. | Product Hunt

 

MySQL: INSERT … ON DUPLICATE KEY UPDATE …

MySQL bietet die Möglichkeit, beim Ausführen eines INSERT INTO ein UPDATE auszuführen, falls es beim Einfügen des Datensatzes zu einem dublicate key kommt. Dies lässt sich mit folgender Eingabe erzielen:

INSERT INTO <table> (<field1>, <field2>) VALUES (<value1>, <value2>)
ON DUPLICATE KEY UPDATE <field2> = <field2> + 1;

Sollte es bei der Ausführung der INSERT-Anweisung zu einem doppelten Eintrag in einer als PRIMARY KEY oder UNIQUE KEY definierten Spalte kommen, dann wendet MySQL die UPDATE-Anweisung auf den Datensatz an, der zu dem doppelten Inhalten führt.