Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab CI Runner, how to use volumes or mounts in service containers

I use GitLab CI Runner, it uses the command:

docker run -d --name postgres postgres:9.4

I want to do something like this:

docker run -d --name postgres --volumes-from postgres_datastore postgres:9.4

But GitLab CI Runner doesn't support any options (-v or --volumes-from).

Is there any other way?

like image 597
Eric Avatar asked Apr 13 '16 12:04

Eric


People also ask

Can you mount volume to running docker container?

How to Mount Local Directories using docker run -v. Using the parameter -v allows you to bind a local directory. -v or --volume allows you to mount local directories and files to your container. For example, you can start a MySQL database and mount the data directory to store the actual data in your mounted directory.

How do I mount a container volume to a host?

You can mount host volumes by using the -v flag and specifying the name of the host directory. Everything within the host directory is then available in the container. What's more, all the data generated inside the container and placed in the data volume is safely stored on the host directory.

Which option allows containers to run with persistent volumes?

Docker has an option to allow specific folders in a container to be mapped to the normal filesystem on the host. This allows us to have data in the container without making the data part of the Docker image, and without being bound to AUFS.

What is the difference between bind mount and volume in docker?

Though both methods are similar, there is a slight difference. Docker manages Volumes and is usually not affected by other processes running on the same host. In contrast, Bind Mounts are just directories on the host file system and may be modified by other processes other than docker.


1 Answers

The Docker volumes-from option is not yet available in Gitlab CI Runner (see this PR), however you can configure host mounts and volumes:

[runners.docker]
  volumes = ["/host/path:/target/path:rw", "/some/path"]

The above example would mount /host/path at /target/path/ inside the container and also create a new volume container at /some/path.

See the Gitlab CI Runner manual for all docker related options.

Edit:

For service containers it seems you can only define volumes via the dockerfile of the service image. Maybe enough depending on your requirements.

like image 96
Erik Dannenberg Avatar answered Sep 28 '22 00:09

Erik Dannenberg