Docker container print to the docker ps status filed (health: starting) - docker

I noticed that gitlab image container when starting adds additional info to the status field of the docker ps command:
Up 19 seconds (health: starting)
once its got ready the status changed to:
Up 3 minutes (healthy)
Usually there is no information in brackets present but gitlab somehow manages to print that additional text to the status field.
How to print an arbitrary text to the status field when running container? Should this be done inside the Dockerfile or the running container should have a process that outputs the text that appears in status field of docker ps?
to run gitlab you may use this script:
#!/bin/sh
set -e;
set -f;
export GITLAB_HOME="/tmp/gitlab/srv/gitlab";
mkdir -p "$GITLAB_HOME";
mkdir -p "$GITLAB_HOME/var/opt/gitlab";
mkdir -p "$GITLAB_HOME/var/log/gitlab";
mkdir -p "$GITLAB_HOME/etc/gitlab";
docker run --detach \
--publish 443:443 --publish 80:80 --publish 22:22 \
--name gitlab \
--volume $GITLAB_HOME/config:/etc/gitlab \
--volume $GITLAB_HOME/logs:/var/log/gitlab \
--volume $GITLAB_HOME/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
after running it run
docker ps
to see the additional text in the status field, after approx 1min it should change to (healthy)

Related

starting a NIFI container with my template/flow automatically loaded

i want to create a NIFI container and pass it a template/flow to be loaded automatically when the container is being created (without human intervention).
couldn't find any volumes/environments that are related to it.
i tried using (suggested by chatGPT):
docker run -d -p 8443:8443 \
-v /path/to/templates:/templates \
-e TEMPLATE_FILE_PATH=/templates/template.xml \
--name nifi apache/nifi
and
docker run -d -p 8443:8443 \
-e NIFI_INIT_FLOW_FILE=/Users/l1/Desktop/kaleidoo/devops/files/git_aliases/flow.json \
-v /Users/l1/Desktop/kaleidoo/docker/test-envs/flow.json:/flow.json:ro \
--name nifi apache/nifi
non of them worked, and i couldn't find data about NIFI_INIT_FLOW_FILE and TEMPLATE_FILE_PATH in the documentation.

Hide portainer container from containers list

How can I hide the portainer container from the Portainer's container list?
Inside a console, run:
docker pull portainer/portainer-ce:latest && \
echo "FROM portainer/portainer-ce:latest" | docker build --label hidden="true" -t "portainer/portainer-ce:latest" -
This will create a new image of Portainer, with the label hidden="true" applied.
Then, re-install the Portainer's docker container:
docker stop portainer && \
docker rm portainer && \
docker run -d -p 8000:8000 -p 9000:9000 \
--name=portainer --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data portainer/portainer-ce
Open Portainer at http://localhost:8000, go to "Settings" (bottom left), at the "Hidden containers" section, and add an entry with name=hidden, value=true:
Now the portainer's container won't be visible at the containers list.

How to completely erase a Docker container of GitLab Server from machine?

While writing an automated deployment script for a self-hosted GitLab server I noticed that my uninstallation script does not (completely) delete the GitLab server settings, nor repositories. I would like the uninstaller to completely remove all traces of the previous GitLab server installation.
MWE
#!/bin/bash
uninstall_gitlab_server() {
gitlab_container_id=$1
sudo systemctl stop docker
sudo docker stop gitlab/gitlab-ce:latest
sudo docker rm gitlab/gitlab-ce:latest
sudo docker rm -f gitlab_container_id
}
uninstall_gitlab_server <some_gitlab_container_id>
Observed behaviour
When running the installation script, the GitLab repositories are preserved, and the GitLab root user account password is preserved from the previous installation.
Expected behaviour
I would expect the docker container and hence GitLab server data to be erased from the device. Hence, I would expect the GitLab server to ask for a new root password, and I would expect it to not display previously existing repositories.
Question
How can I completely remove the GitLab server that is installed with:
sudo docker run --detach \
--hostname $GITLAB_SERVER \
--publish $GITLAB_PORT_1 --publish $GITLAB_PORT_2 --publish $GITLAB_PORT_3 \
--name $GITLAB_NAME \
--restart always \
--volume $GITLAB_HOME/config:/etc/gitlab \
--volume $GITLAB_HOME/logs:/var/log/gitlab \
--volume $GITLAB_HOME/data:/var/opt/gitlab \
-e GITLAB_ROOT_EMAIL=$GITLAB_ROOT_EMAIL -e GITLAB_ROOT_PASSWORD=$gitlab_server_password \
gitlab/gitlab-ce:latest)
Stopping and removing the containers doesn't remove any host/Docker volumes you may have mounted/created.
--volume $GITLAB_HOME/config:/etc/gitlab \
--volume $GITLAB_HOME/logs:/var/log/gitlab \
--volume $GITLAB_HOME/data:/var/opt/gitlab \
You need to rm -rf $GITLAB_HOME

How can I use my saved volume data after restarting docker?

I have a Docker container based on Linux on a PC running Windows. I have pulled and installed Gitlab CI/CD. Everything is running and I log in to Gitlab, but every time I restart the docker container it is like I lose all my data. I understand it overrides the previous data, saved inside the container, but I need a way to "persist" that data. From my understanding the only way is to point the volumes of the Gitlab image to directories saved on my PC somehow. How do I do this or something similar to this so I won't lose my data on Docker restart?
The script I ran to instantiate gitlab image is the following:
docker run -d --hostname gitlab.wproject.gr \
-p 4433:443 -p 80:80 -p 2223:22 \
--name gitlab-server1 \
--restart always \
--volume /storage/gitlab/config:/etc/gitlab \
--volume /storage/gitlab/logs:/var/log/gitlab \
--volume /storage/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
Try to put relative links for your volumes instead of absolute links. If you use Docker Desktop on Windows the volume management doesn't always behave the same way as on Linux.
Test with:
mkdir gitlab
docker run -d --hostname gitlab.wproject.gr \
-p 4433:443 -p 80:80 -p 2223:22 \
--name gitlab-server1 \
--restart always \
--volume ./gitlab/config:/etc/gitlab \
--volume ./gitlab/logs:/var/log/gitlab \
--volume ./gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest

What to do or how to handle if health_status of a docker container changes

I am running a docker container with health-cmd and I know it will turn to unhealthy when it stops working.
$ docker run
--name=some-container \
--health-cmd='curl -sS http://127.0.0.1:5000 || exit 1' \
--health-timeout=10s \
--health-retries=3 \
--health-interval=5s \
--restart on-failure \
container-image
I want to restart the container when it changes its health-status. How can do that? How to trigger the restart?
My Docker version 19.03.1, build 74b1e89
depends on your Dockerfile if the health check faild the container is exited with the code 1 becaus of your command :
--health-cmd='curl -sS http://127.0.0.1:5000 || exit 1'
therefore your restart policy on-failure will restart the container after ~35 seconds timeout + retries + interval when only the check failed.
the timeout + retries + interval values you can determind on many conditions there is no perfect values for them.
I think your command are good to go
You can use autoheal to restart unhealthy docker containers.
Sample:
docker run -d \
--name autoheal \
--restart=always \
-e AUTOHEAL_CONTAINER_LABEL=all \
-v /var/run/docker.sock:/var/run/docker.sock \
willfarrell/autoheal
Note: You must apply HEALTHCHECK to your docker images first. See https://docs.docker.com/engine/reference/builder/#healthcheck for details.

Resources