
Containers are meant to be ephemeral and so scale pretty well for stateless applications. Stateful containers, such as Couchbase, need to be treated differently. Managing Persistence for Docker Containers provide a great overview of how to manage persistence for stateful containers.
This blog will explain how to use Docker Volume Plugins 그리고 Portworx to create a stateful container.
Why Portworx?
Portworx is an easy-to-deploy container data services that provide persistence, replication, snapshots, encryption, secure RBAC and much more. Some of the benefits are:
- Container granular volumes – Portworx can take multiple EBS volumes per host and aggregate the capacity and derive container granular virtual (soft) volumes per container.
- Cross Availability Zone HA – Portworx will protect the data, at block level, across multiple compute instances across availability zones. As replication controllers restart pods on different nodes, the data will still be highly available on those nodes.
- Support for enterprise data operations – Portworx implements container granular snapshots, class of service, tiering on top of the available physical volumes.
- Ease of deployment and provisioning – Portworx itself is deployed as a container and integrated with the orchestration tools. DevOps can programmatically provision container granular storage with any property such as size, class of service, encryption key etc.
Setup AWS EC2 Instance
Portworx runs only on Linux or CoreOS. Setup an Ubuntu instance on AWS EC2:
- Start Ubuntu 14.04 instance with
m3.mediuminstance type. Make sure to add port 8091 to inbound security rules. This allows 카우치베이스 웹 콘솔 to be accessible afterwards. - Login to the EC2 instance using the command:
ssh -i ~/.ssh/arun-cb-west1.pem ubuntu@<public-ip> - Update the Ubuntu instance:
sudo apt-get update - Install Docker:
curl -sSL https://get.docker.com/ | sh. More detailed instructions are available at Get Docker for Ubuntu. - Enable non-root access for the docker command:
sudo usermod -aG docker ubuntu - Logout from the EC2 instance and log back in
Create AWS EBS Volume
- Create an EBS volume for 10GB using EC2 console as explained in docs.
- Get the instance id from the EC2 console. Attach this volume to EC2 instance using this instance id, use the default device name
/dev/sdf.

- Use
lsblkcommand in EC2 instance to verify that the volume is attached to the instance:NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 8G 0 disk └─xvda1 202:1 0 8G 0 part / xvdb 202:16 0 30G 0 disk /mnt xvdf 202:80 0 10G 0 disk
Portworx Container
- Physical storage makeup of each node, all the provisioned volumes in the cluster as well as their container mappings is stored in an etcd cluster. Start an etcd cluster:
12345도커 실행 –v/데이터/varlib/etcd–p 4001:4001–dportworx/etcd:latest
- By default root mounted volumes are not allowed to be shared. Enable this using the command:
1sudo mount —make–shared /
This is explained more at Ubuntu Configuration and Shared Mounts.
- PX-Developer (px-dev) container on a server with Docker Engine turns that server into a scale-out storage node. PX-Enterprise, on the other hand, provides multi-cluster and multi-cloud support, where storage under management can be on-premise or in a public cloud like AWS.
For this blog, we’ll start a px-dev container:123456789101112도커 실행 —restart=항상 —이름 px –d —네트=host—privileged=참인–v /실행/도커/plugins:/실행/도커/plugins–v /변수/lib/osd:/변수/lib/osd:shared–v /개발자:/개발자–v /etc/pwx:/etc/pwx–v /opt/pwx/bin:/export_bin:shared–v /변수/실행/도커.sock:/변수/실행/도커.sock–v /변수/cores:/변수/cores–v /usr/소스:/usr/소스—ipc=hostportworx/px–개발자 –데몬 –k etcd://localhost:4001 -c cluster1 -s /dev/xvdfComplete details about this command are available at Run PX with Docker.
- Look for logs using
docker container logs -f pxand watch out for the following statements:1234시간=“2017-02-16T05:33:26Z” 레벨=정보 msg=“Initialize the scheduler client and the scheduler watch”시간=“2017-02-16T05:33:26Z” 레벨=정보 msg=“Started a kvdb watch on key : scheduler/containers”시간=“2017-02-16T05:33:26Z” 레벨=정보 msg=“Started a kvdb watch on key : scheduler/volumes”시간=“2017-02-16T05:33:26Z” 레벨=정보 msg=“Started a kvdb watch on key : scheduler/nodes/list” - Check the status of attached volumes that are available to Portworx using
sudo /opt/pwx/bin/pxctl statusto see the output:12345678910111213141516상태: PX 이다 operationalNode 아이디: 679b79b1–f4c3–413e–a8e0–c527348647c9IP: 172.31.25.21Local 저장 공간 Pool: 1 poolPool IO_Priority Size Used 상태 Zone Region0 LOW 10 GiB 266 맨인블랙 Online a us–west–1Local 저장 공간 Devices: 1 deviceDevice Path 미디어 입력 Size Last–Scan0:1 /개발자/xvdf STORAGE_MEDIUM_SSD 10 GiB 16 Feb 17 05:33 UTC전체 – 10 GiB클러스터 요약클러스터 아이디: cluster1Node IP: 172.31.25.21 – Capacity: 266 맨인블랙/10 GiB Online (이것 node)Global 저장 공간 PoolTotal Used : 266 맨인블랙Total Capacity : 10 GiBIt shows the total capacity available and used.
Docker Volume
- Let’s create a Docker volume:
1도커 volume 만들다 –d pxd –o size=10G –o fs=ext4 —이름 cbvol
More details about this command are at Create Volumes with Docker.
- Check the list of volumes available using
docker volume lscommand:1234DRIVER VOLUME NAME로컬 70f7b9a356df4c1f0c08e13a4e813f1ef3e174a91001f277a63b62d683a27159pxd cbvol로컬 f7bc5fa455a88638c106881f1bce98244b670e094d5fdc47917b53a88e46c073As shown,
cbvolis created withpxddriver.
Couchbase with Portworx Volume
- Create a Couchbase container using the Portworx volume:
1234567도커 컨테이너 실행–d—이름 db–v cbvol:/opt/카우치베이스/변수–p 8091–8094:8091–8094–p 11210:11210arungupta/카우치베이스
Notice how
/opt/couchbase/varwhere all Couchbase data is stored in the container is mapped to thecbvolvolume on the host. This volume is mapped by Portworx. - Login to Couchbase Web Console at https://<public-ip>:8091, use the login
관리자그리고비밀번호as password. - Go to Data Buckets and create a new data bucket pwx:

- In EC2 instance, see the list of containers:
12345ubuntu@IP–172–31–25–21:~$ 도커 컨테이너 lsCONTAINER 아이디 IMAGE COMMAND CREATED STATUS PORTS NAMES8ae763d9d53b arungupta/카우치베이스 “/entrypoint.sh /o…” 5 minutes ago Up 5 minutes 0.0.0.0:8091–8094->8091–8094/tcp, 11207/tcp, 11211/tcp, 0.0.0.0:11210->11210/tcp, 18091–18093/tcp db5423bcd9b426 portworx/px–개발자 “/docker-entry-poi…” 14 minutes ago Up 14 minutes pxcf3c779a4459 portworx/etcd:latest “/entrypoint.sh /b…” 21 minutes ago Up 21 minutes 2379–2380/tcp, 7001/tcp, 0.0.0.0:4001->4001/tcp youthful_jepsen
etcd,px-dev그리고dbcontainers are running. - Kill the
dbcontainer:1도커 컨테이너 rm –f db - Restart the database container as:
01sudo mount —make–shared /
Now, because
cbvolis mapped to/opt/couchbase/varagain, the data is preserved across restarts. This can be verified by accessing the Couchbase Web Consoleand checking on thepwxbucket created earlier.
Another interesting perspective is also at why database are not for containers?. Just because there is Docker, does not mean all your database needs should be Dockerized. But if you need to, then there are plenty of options and can be used in production-grade applications.
Want to learn more about running Couchbase in containers?
작가
1개의 응답
-
[…] Source: blog.couchbase.com/stateful-docker-containers-portworx-couchbase/ […]

댓글 남기기
댓글을 달기 위해서는 로그인해야합니다.