Deploy Sync Gateway with Docker
Deploy Sync Gateway using Docker; securely sync enterprise data from cloud to edge.
This is an alternative to the Install and Configure steps in the Start Here! topic group. It deploys {sgw} and {cbs} using Docker containers.
|
Preparatory Steps
Make sure you have read and acted-upon the information in Prepare before proceeding.
|
- Steps in Getting Started
-
Introduction | Prepare | Install | Configure
Before You Begin
Make sure you have:
-
Docker installed on your machine. See the Docker installation guide for instructions.
-
The bucket name and RBAC credentials from Prepare.
Deploy Couchbase Server
Create a Docker Network
Create a Docker bridge network so that Couchbase Server and Sync Gateway containers can communicate.
docker network create --driver bridge couchbase
Run Couchbase Server
Run Couchbase Server in a Docker container on the couchbase network.
docker run -d --name cb-server \
--network couchbase \
-p 8091-8097:8091-8097 \
-p 11210-11211:11210-11211 \
couchbase/server
Configure Couchbase Server
Once Couchbase Server is running, open the Admin UI at http://localhost:8091 and complete the setup described in Prepare, including:
-
Creating a cluster
-
Creating a bucket
-
Creating an RBAC user for sync gateway
| Note the bucket name and RBAC credentials. You will need them in the next step. |
Deploy Sync Gateway
Create a Configuration File
Create a configuration file named sync-gateway-config.json on your local machine.
Replace <rbac-username> and <rbac-password> with the credentials you set up in Couchbase Server.
{
"bootstrap": {
"server": "couchbase://cb-server", (1)
"username": "<rbac-username>", (2)
"password": "<rbac-password>",
"use_tls_server": false (3)
},
"logging": {
"console": {
"enabled": true,
"log_level": "info",
"log_keys": ["*"]
}
}
}
| 1 | Use the Couchbase Server container name cb-server as the hostname.
Docker resolves this name within the couchbase network. |
| 2 | Use the RBAC credentials you created when you configured Couchbase Server. |
| 3 | TLS is disabled for local development.
For production deployments, enable TLS and use couchbases://cb-server instead. |
Run Sync Gateway
Run sync gateway in a Docker container, mounting the configuration file you created.
Replace /path/to/sync-gateway-config.json with the absolute path to the file on your local machine.
docker run -d --name sync-gateway \
--network couchbase \
-p 4984-4985:4984-4985 \
-v /path/to/sync-gateway-config.json:/etc/sync_gateway/config.json \
couchbase/sync-gateway \
/etc/sync_gateway/config.json
| Port 4985 is the sync gateway Admin port. By default it is only accessible from within the container. Do not expose port 4985 to external traffic in production environments. |
Verify the Connection
-
Point your browser to the sync gateway public port:
http://localhost:4984 -
Confirm that you receive a response similar to this:
{"couchdb":"Welcome","vendor":{"name":"Couchbase Sync Gateway","version":"4.0"},"version":"Couchbase sync gateway/4.0.0 EE"}If there are issues, select the Console Logs for more information.
Manage Your Containers
Start Containers
Start Couchbase Server before sync gateway.
docker start cb-server
docker start sync-gateway
| If Couchbase Server is stopped for an extended period, sync gateway loses the connection. Restart sync gateway after restarting Couchbase Server. |
Update the Sync Gateway Configuration
To update the sync gateway configuration, stop and remove the container, then re-run it with the updated configuration file.
docker stop sync-gateway
docker rm sync-gateway
Then repeat Run Sync Gateway.
Next Steps
Now that you have sync gateway running in Docker, continue to Explore to add a database configuration, create users, and run a CRUD cycle to confirm sync is working end-to-end.
From there, you can explore more complex scenarios:
-
Learn more about sync gateway’s Bootstrap Configuration
-
Learn how to Sync with Couchbase Server
-
Implement access controls — see: Users, Roles, and the Sync Function