How can I use my saved volume data after restarting docker? - 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

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.

How to push files from docker Jenkins to local dir

I am new to the Jenkins and docker. I wonder if there is way to push the files from container to local. I mounted local dir to docker, but it seems all files only updated in container.
local dir: /home/xyz/
container dir: /var/jenkins_home/xyz
docker run \
--name jenkins \
--restart=on-failure \
--detach \
--network jenkins \
--env DOCKER_HOST=tcp://docker:2376 \
--env DOCKER_CERT_PATH=/certs/client \
--env DOCKER_TLS_VERIFY=1 \
--publish 8080:8080 \
--publish 50000:50000 \
--mount type=bind,source=/home/xyz/,target=/var/jenkins_home/xyz \
--volume jenkins-data:/var/jenkins_home \
--volume jenkins-docker-certs:/certs/client:ro \
myjenkins-blueocean:2.361.3-1
When you ran Jenkins image using --volume jenkins-data:/var/jenkins_home you used docker volumes. Docker manages the volume and you can find the exact data location by inspecting the volumes of the container.
When you used --mount type=bind,source=/home/xyz/,target=/var/jenkins_home/xyz you mapped the folder /var/jenkins_home/xyz from the container to folder /home/xyz/ on the docker host using bind mounts. Jenkins home data changes in the container are reflected on the host path. Create a new job and you will see its definition in jobs folder.
You should use either docker volumes or bind mounts, not both for a single data folder.
If you want to copy data from the container to the host use docker cp command.

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

Multiple Teamcity agents with Docker

Ok,
I can somewhat sense my question has nothing to do with Teamcity but rather the subtle issues surrounding docker. I am trying to fire off one Teamcity agent with
docker run -it -d -e SERVER_URL="192.168.100.15:8111" \
--restart always \
--name="teamcity-agent_1" \
--mount src=docker_volumes_1,dst=/var/lib/docker,type=volume \
--mount src=$(pwd)/config,dst=/etc/docker,type=bind \
--privileged -e DOCKER_IN_DOCKER=start \
jetbrains/teamcity-agent
Works like a charm. Then I try to fire off a second agent (up to three agents are free). This used to work perfectly fine but has recently stopped...
docker run -it -d -e SERVER_URL="192.168.100.15:8111" \
--restart always \
--name="teamcity-agent_2" \
--mount src=docker_volumes_2,dst=/var/lib/docker,type=volume \
--mount src=$(pwd)/config,dst=/etc/docker,type=bind \
--privileged -e DOCKER_IN_DOCKER=start \
jetbrains/teamcity-agent
In this second container docker wouldn't start, e.g. docker images results in
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
service docker start
service docker status
Confirm that I have successfully started docker but then going back to docker images and we get the same problem as above. service docker status tells me now that docker is not running!

How to set heap memory in cassandra on docker

I am using a Cassandra docker (official Cassandra docker) to setup my local env.
As part of this I want to limit the amount of memory the Cassandra is using in my local deployment.
By default Cassandra has a pre defined way to set its memory.
I found references to some info saying that i can use JVM_OPTS to set this values but it does not seem to take hold.
I am looking for a way to set up this values without creating my own Cassandra docker.
Docker command that is used to run container:
docker run -dit --name sdc-cs --env RELEASE="${RELEASE}" \
--env CS_PASSWORD="${CS_PASSWORD}" --env ENVNAME="${DEP_ENV}" \
--env HOST_IP=${IP} --env JVM_OPTS="-Xms1024m -Xmx1024m" \
--log-driver=json-file --log-opt max-size=100m \
--log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 \
--volume /etc/localtime:/etc/localtime:ro \
--volume ${WORKSPACE}/data/CS:/var/lib/cassandra \
--volume ${WORKSPACE}/data/environments:/root/chef-solo/environments \
--publish 9042:9042 --publish 9160:9160 \
${PREFIX}/sdc-cassandra:${RELEASE} /bin/s
Any advice will be appreciated!
I am using docker-compose, in the docker-compose.yml file I set the following env variables. It seems to work.
environment:
- HEAP_NEWSIZE=128M
- MAX_HEAP_SIZE=2048M
Entrypoint script starts cassandra as usual, and during start it executes cassandra-env.sh script that may set memory options if they aren't set in the JVM_OPTS environment variable, so if you start container with corresponding memory options set via -e JVM_OPTS..., then it should work.
But in a long run it's better to submit config files via /config mount point of Docker image, and put memory option into jvm.options file that is loaded by cassandra-env.sh.
P.S. Just tried it on my machine:
docker run --rm -e DS_LICENSE=accept store/datastax/dse-server:5.1.5
Gives me following memory switches: -Xms1995M -Xmx1995M.
If I run it with:
docker run --rm -e DS_LICENSE=accept \
-e JVM_OPTS="-Xms1024M -Xmx1024M" store/datastax/dse-server:5.1.5
then it gives correct -Xms1024M -Xmx1024M...

Resources