a.t.
a.t.

Reputation: 2749

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)

Upvotes: 0

Views: 417

Answers (1)

OneCricketeer
OneCricketeer

Reputation: 191874

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

Upvotes: 1

Related Questions