Skip to content

Commit 9cdc815

Browse files
janhoyjebnix
andauthored
Clean up docker-faq.adoc (#2277)
Co-authored-by: Jeb Nix <[email protected]>
1 parent 2e09660 commit 9cdc815

File tree

1 file changed

+13
-160
lines changed

1 file changed

+13
-160
lines changed

solr/solr-ref-guide/modules/deployment-guide/pages/docker-faq.adoc

Lines changed: 13 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -18,141 +18,35 @@
1818

1919
== How do I persist Solr data and config?
2020

21-
Your data is persisted already, in your container's filesystem.
22-
If you `docker run`, add data to Solr, then `docker stop` and later `docker start`, then your data is still there.
23-
The same is true for changes to configuration files.
24-
25-
Equally, if you `docker commit` your container, you can later create a new
26-
container from that image, and that will have your data in it.
27-
28-
For some use-cases it is convenient to provide a modified `solr.in.sh` file to Solr.
29-
For example to point Solr to a ZooKeeper host:
30-
31-
[source,bash]
32-
----
33-
docker create --name my_solr -P solr
34-
docker cp my_solr:/opt/solr/bin/solr.in.sh .
35-
sed -i -e 's/#ZK_HOST=.*/ZK_HOST=cylon.lan:2181/' solr.in.sh
36-
docker cp solr.in.sh my_solr:/opt/solr/bin/solr.in.sh
37-
docker start my_solr
38-
# With a browser go to http://cylon.lan:32873/solr/#/ and confirm "-DzkHost=cylon.lan:2181" in the JVM Args section.
39-
----
40-
41-
But usually when people ask this question, what they are after is a way
42-
to store Solr data and config in a separate https://docs.docker.com/userguide/dockervolumes/[Docker Volume].
43-
That is explained in the next two questions.
21+
Solr's Docker image is pre-configured with container path `/var/solr/` as a https://docs.docker.com/storage/volumes/[volume].
22+
What this means is that all index data, log files and other variable data will be
23+
persisted on the Docker host, even if you remove the container instance.
4424

4525
== How can I mount a host directory as a data volume?
4626

47-
This is useful if you want to inspect or modify the data in the Docker host
48-
when the container is not running, and later easily run new containers against that data.
49-
This is indeed possible, but there are a few gotchas.
50-
51-
Solr stores its core data in the `server/solr` directory, in sub-directories for each core.
52-
The `server/solr` directory also contains configuration files that are part of the Solr distribution.
53-
Now, if we mounted volumes for each core individually, then that would interfere with Solr trying to create those directories.
54-
If instead we make the whole directory a volume, then we need to provide those configuration files in our volume, which we can do by copying them from a temporary container.
55-
For example:
27+
By default Solr's volume is persisted in Docker's default storage location on the host.
28+
On Linux systems this is `/var/lib/docker/volumes`. This is the recommended way to
29+
store Solr's data. You have flexibility to use a bind mount host folder as well:
5630

5731
[source,bash]
5832
----
59-
# create a directory to store the server/solr directory
60-
mkdir /home/docker-volumes/mysolr1
61-
62-
# make sure its host owner matches the container's solr user
63-
sudo chown 8983:8983 /home/docker-volumes/mysolr1
64-
65-
# copy the solr directory from a temporary container to the volume
66-
docker run -it --rm -v /home/docker-volumes/mysolr1:/target solr cp -r server/solr /target/
67-
68-
# pass the solr directory to a new container running solr
69-
SOLR_CONTAINER=$(docker run -d -P -v /home/docker-volumes/mysolr1/solr:/opt/solr/server/solr solr)
70-
71-
# create a new core
72-
docker exec -it --user=solr $SOLR_CONTAINER solr create -c gettingstarted
73-
74-
# check the volume on the host:
75-
ls /home/docker-volumes/mysolr1/solr/
76-
# configsets gettingstarted README.txt solr.xml zoo.cfg
33+
docker run --rm -p 8983:8983 -v $(pwd)/myData:/var/solr/ solr:9-slim
7734
----
7835

79-
Note that if you add or modify files in that directory from the host, you must `chown 8983:8983` them.
80-
81-
== How can I use a Data Volume Container?
82-
83-
You can avoid the concerns about UID mismatches above, by using data volumes only from containers.
84-
You can create a container with a volume, then point future containers at that same volume.
85-
This can be handy if you want to modify the solr image, for example if you want to add a program.
86-
By separating the data and the code, you can change the code and re-use the data.
87-
88-
But there are pitfalls:
89-
90-
* if you remove the container that owns the volume, then you lose your data.
91-
Docker does not even warn you that a running container is dependent on it.
92-
* if you point multiple solr containers at the same volume, you will have multiple instances
93-
write to the same files, which will undoubtedly lead to corruption
94-
* if you do want to remove that volume, you must do `docker rm -v containername`;
95-
if you forget the `-v` there will be a dangling volume which you can not easily clean up.
96-
97-
Here is an example:
98-
99-
[source,bash]
100-
----
101-
# create a container with a volume on the path that solr uses to store data.
102-
docker create -v /opt/solr/server/solr --name mysolr1data solr /bin/true
103-
104-
# pass the volume to a new container running solr
105-
SOLR_CONTAINER=$(docker run -d -P --volumes-from=mysolr1data solr)
106-
107-
# create a new core
108-
docker exec -it --user=solr $SOLR_CONTAINER solr create -c gettingstarted
109-
110-
# make a change to the config, using the config API
111-
docker exec -it --user=solr $SOLR_CONTAINER curl http://localhost:8983/solr/gettingstarted/config -H 'Content-type:application/json' -d '{
112-
"set-property" : {"query.filterCache.autowarmCount":1000},
113-
"unset-property" :"query.filterCache.size"}'
114-
115-
# verify the change took effect
116-
docker exec -it --user=solr $SOLR_CONTAINER curl http://localhost:8983/solr/gettingstarted/config/overlay?omitHeader=true
117-
118-
# stop the solr container
119-
docker exec -it --user=solr $SOLR_CONTAINER bash -c 'cd server; java -DSTOP.PORT=7983 -DSTOP.KEY=solrrocks -jar start.jar --stop'
120-
121-
# create a new container
122-
SOLR_CONTAINER=$(docker run -d -P --volumes-from=mysolr1data solr)
123-
124-
# check our core is still there:
125-
docker exec -it --user=solr $SOLR_CONTAINER ls server/solr/gettingstarted
126-
127-
# check the config modification is still there:
128-
docker exec -it --user=solr $SOLR_CONTAINER curl http://localhost:8983/solr/gettingstarted/config/overlay?omitHeader=true
129-
----
36+
But this is both dependent on the host operating system and may run into different kind
37+
of file system permission issues.
13038

13139
== Can I use volumes with SOLR_HOME?
13240

133-
Solr supports a SOLR_HOME environment variable to point to a non-standard location of the Solr home directory.
134-
You can use this in Solr docker, in combination with volumes:
135-
136-
[source,bash]
137-
----
138-
docker run -it -v $PWD/mysolrhome:/mysolrhome -e SOLR_HOME=/mysolrhome solr
139-
----
140-
141-
This does need a pre-configured directory at that location.
142-
143-
To make this easier, Solr docker supports a INIT_SOLR_HOME setting, which copies the contents
144-
from the default directory in the image to the SOLR_HOME (if it is empty).
41+
While you could re-define `SOLR_HOME` inside the container, we instead recommend you
42+
to use the existing `SOLR_HOME` defined at `/var/solr/`, see above. You can give the
43+
volume a meaningful name instead of the auto generated hash, example name `solrData`:
14544

14645
[source,bash]
14746
----
148-
mkdir mysolrhome
149-
sudo chown 8983:8983 mysolrhome
150-
docker run -it -v $PWD/mysolrhome:/mysolrhome -e SOLR_HOME=/mysolrhome -e INIT_SOLR_HOME=yes solr
47+
docker run --rm -p 8983:8983 -v solrData:/mysolrhome solr:9-slim
15148
----
15249

153-
NOTE: If SOLR_HOME is set, the "solr-precreate" command will put the created core in the SOLR_HOME directory
154-
rather than the "mycores" directory.
155-
15650
== Can I run ZooKeeper and Solr clusters under Docker?
15751

15852
At the network level the ZooKeeper nodes need to be able to talk to each other,
@@ -180,47 +74,6 @@ It also has a `--ip-range` option that allows you to specify the range that othe
18074
Used together, you can implement static addresses.
18175
See the xref:docker-networking.adoc[] for more information.
18276

183-
== Can I run ZooKeeper and Solr with Docker Links?
184-
185-
Docker's https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/[Legacy container links] provide a way to
186-
pass connection configuration between containers.
187-
It only works on a single machine, on the default bridge.
188-
It provides no facilities for static IPs.
189-
Note: this feature is expected to be deprecated and removed in a future release.
190-
So really, see the "Can I run ZooKeeper and Solr clusters under Docker?" option above instead.
191-
192-
But for some use-cases, such as quick demos or one-shot automated testing, it can be convenient.
193-
194-
Run ZooKeeper, and define a name so we can link to it:
195-
196-
[source,bash]
197-
----
198-
docker run --name zookeeper -d -p 2181:2181 -p 2888:2888 -p 3888:3888 jplock/zookeeper
199-
----
200-
201-
Run two Solr nodes, linked to the zookeeper container:
202-
203-
[source,bash]
204-
----
205-
docker run --name solr1 --link zookeeper:ZK -d -p 8983:8983 \
206-
solr \
207-
bash -c 'solr start -f -z $ZK_PORT_2181_TCP_ADDR:$ZK_PORT_2181_TCP_PORT'
208-
209-
docker run --name solr2 --link zookeeper:ZK -d -p 8984:8983 \
210-
solr \
211-
bash -c 'solr start -f -z $ZK_PORT_2181_TCP_ADDR:$ZK_PORT_2181_TCP_PORT'
212-
----
213-
214-
Create a collection:
215-
216-
[source,bash]
217-
----
218-
docker exec -i -t solr1 solr create \
219-
-c gettingstarted -shards 2 -p 8983
220-
----
221-
222-
Then go to `+http://localhost:8983/solr/#/~cloud+` (adjust the hostname for your docker host) to see the two shards and Solr nodes.
223-
22477
== How can I run ZooKeeper and Solr with Docker Compose?
22578

22679
See the xref:solr-in-docker.adoc#docker-compose[docker compose example].

0 commit comments

Comments
 (0)