How can I get scm manager running in a docker container to use an existing directory on the host system for configuration and repos - scmmanager

When I start scm manager via docker:
docker run sdorra/scm-manager
How do I get scm manager to retrieve/store its configuration data and repositories from/to an existing directory on the main filesystem?

You can use docker volumes to achieve this. With a docker volume you can mount a folder from your host into your container. In the case of the scm-manager home directory this could look like this:
docker run -v /host/path:/var/lib/scm sdorra/scm-manager:1.60
The left side of the "-v" parameter specifies the path on the host filesystem and the right side specifies the path in the container.
Note: The scm-manager docker container uses a user with the uid 1000, so you have to be sure that the user can read and write this volume: chown -R 1000:1000 /host/path.

Related

Change mountpoint of docker volume to a custom directory

I would like to have a Docker Volume that mounts to a container. This volume would need to be somewhere other than the default location of volumes, preferably somewhere on the Desktop. This is because I am running a web server and would like some directories to be editable by something like VSCode so I don't always have to go inside the container to edit a file. I am not going to be using Docker Compose and instead will be using a Docker File for the container. The functionality I'm going for is the following equivalent of Docker Compose, but in a Dockerfile or through docker run, whichever is easiest to accomplish:
volumes:
- <local-dir>:<container-dir>
This directory will need to be editable LIVE and using the Dockerfile ADD command will not suffice, because after building, the image gets put into a tar archive and cannot be accessed after that.
with this solution you can move even A live container to new partition:
Add a configuration file to tell the docker daemon what is the location of the data directory
Using your preferred text editor add a file named daemon.json under the directory /etc/docker. The file should have this content:
{
"data-root": "/path/to/your/docker"
}
Copy the current data directory to the new one
sudo rsync -aP /var/lib/docker/ /path/to/your/docker
Rename the old docker directory
sudo mv /var/lib/docker /var/lib/docker.old
Restart the docker daemon
sudo service docker start
resource: https://www.guguweb.com/2019/02/07/how-to-move-docker-data-directory-to-another-location-on-ubuntu/
You can mount a directory from your host inside your container when you launch the docker container, using -v or --volume
docker run -v /path/to/desktop/some-dir:/container-dir/path <docker-image>
Volumes specified in the Dockerfile, as you exemplified, will automatically create those volumes under /var/lib/docker/volumes/ every time a container is launched from that image, but it is NOT recommended have these volumes altered by non-Docker processes.

how to configure Cassandra.yaml which is inside docker image of cassandra at /etc/cassandra/cassandra.yaml

I am trying to edit cassandra.yaml which is inside docker container at /etc/cassandra/cassandra.yaml, I can edit it from logging inside the container, but how can i do it from host?
Multiple ways to achieve this from host to container. You can simple use COPY or RUN in Dockerfile or with basic linux commands as sed, cat, etc. to place your configuration into the container. Another way you can pass environment variables while running your cassandra image which will pass those environment variables to the spawning container. Also, can use the docker volume mount it from host to container and you can map the configuration you want into the cassandra.yaml as shown below,
$ docker container run -v ~/home/MyWorkspace/cassandra.yaml:/etc/cassandra/cassandra.yaml your_cassandra_image_name
If you are using Docker Swarm then you can use Docker configs to externally store the configuration files(Even other external services can be used as etcd or consul). Hope this helps.
To edit cassandra.yaml :
1) Copy your file from your Docker container to your system
From command line :
docker ps
(To get your container id)
Then :
docker cp your_container_id:\etc\cassandra\cassandra.yaml C:\Users\your_destination
Once the file copied you should be able to see it in your_destination folder
2) Open it and make the changes you want
3) Copy your file back into your Docker container
docker cp C:\Users\your_destination\cassandra.yaml your_container_id:\etc\cassandra
4) Restart your container for the changes to be effective

How to get an artifact generated from a container?

I have a Dockerfile dedicated to run my unit test, but i am not sure how i am supposed to get the coverage directory it generates (inside the container).
I would like to be able to get it as an artifact to be able to analyze it, but is it possible since it is generated from the container?
Use docker cp command
If you want to copy the /tmp/foo directory from a container to the existing /tmp directory on your host. If you run docker cp in your ~ (home) directory on the local host:
$ docker cp container_name:tmp/foo /tmp
Docker creates a /tmp/foo directory on your host.
If your container dies after executing you can map a volume from you host to the container, in this way you will have your data in your host after the container dies.
VOLUME ["/home/data"]
This will map /home/data in your machine with /home/data in your container, adjust at will.
More info
https://docs.docker.com/engine/reference/builder/#notes-about-specifying-volumes

Mount a local directory as volume in container, from the Dockerfile

I know how local directories can be mounted as volumes with the -v option in docker run, i.e.
docker run -v /local/some_folder:/container/some_folder image_name
However, I want to be able to specify the above instruction (to mount the local /local/some_folder as /container/some_folder in the container within the Dockerfile.
I've tried using VOLUME /local/some_folder /container/some_folder in the Dockerfile, but that didn't seem to work: I am then able to access /container/some_folder from within the container using docker exec -t container sh, but the write changes of container to /container/some_folder are not reflected in /local/some_folder during container runtime AND after docker stop container.
You do not have access to control things like host volume mounts inside the Dockerfile or image build process. Allowing this would allow malicious image creators to make an image that mounts directories on the host without the permission of the admin of that host. A security breach that allowed a popular base image to mount the filesystem could be used to send private data off-site and inject login credentials on countless machines. The only way to mount a volume is at run time at the explicit request of the admin running the container, and to the directory they provide.

How to specify volume for docker container in CircleCI configuration?

I did not manage to find out how to mount volume of docker image in config.yml for integrating with CircleCI.
Official document gives those variables for
container usage, entry point, command, etc., but none about volume mounting.
The scenario is, the building of my project requires two docker containers, the main container and the other container for service foo. To use the service foo, I need expose some artifacts generated in earlier steps to foo container and do some next steps.
Anyone has idea whether I can do that?
As taken from CircleCI documentation:
Mounting Folders
It’s not possible to mount a folder from your job space into a container in Remote Docker (and vice versa). But you can use docker cp command to transfer files between these two environments. For example, you want to start a container in Remote Docker and you want to use a config file from your source code for that:
- run: |
# creating dummy container which will hold a volume with config
docker create -v /cfg --name configs alpine:3.4 /bin/true
# copying config file into this volume
docker cp path/in/your/source/code/app_config.yml configs:/cfg
# starting application container using this volume
docker run --volumes-from configs app-image:1.2.3
In the same way, if your application produces some artifacts that need to be stored, you can copy them from Remote Docker:
- run: |
# starting container with our application
# make sure you're not using `--rm` option otherwise container will be killed after finish
docker run --name app app-image:1.2.3
- run: |
# once application container finishes we can copy artifacts directly from it
docker cp app:/output /path/in/your/job/space

Resources