Setting up openstack swift single instance in docker

Image soure:Pixabay

Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.In today’s tutorial we are going to see how to install docker and set up openstack instance in ubuntu.

The steps are as follows:

Docker can be installed using older docker.io package or new docker-engine package.In order to install from docker.io package run the following commands:

sudo apt-get update

sudo apt-get install docker.io

To install from docker-engine run the following commands:

sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo sh -c "echo 'deb https://apt.dockerproject.org/repo ubuntu-$(lsb_release -sc) main' | cat > /etc/apt/sources.list.d/docker.list"
sudo apt-get update
sudo apt-get install docker-engine

To check whether docker is installed correctly run the following command:

sudo su
docker version
Client:
Version: 1.12.3
API version: 1.24
Go version: go1.6.2
Git commit: 6b644ec
Built: Mon, 19 Dec 2016 09:20:48 +1300
OS/Arch: linux/amd64
Server:
Version: 1.12.3
API version: 1.24
Go version: go1.6.2
Git commit: 6b644ec
Built: Mon, 19 Dec 2016 09:20:48 +1300
OS/Arch: linux/amd64

Since docker requires superuser privileges to run correctly it might be a good idea to drop into root user using `sudo su` command.

In order to allow docker service to start on system boot run the following command:

update-rc.d docker enable

Now lets move forward with setting up openstack swift in docker:

First we create persistence storage for our swift container:

docker run -v /srv --name SWIFT_DATA busybox

We are going to use swift dockerfile for single instance which can be found here: Github

In order to create and run the docker container run the following command:

docker run -d --restart=always -p 12345:8080 --volumes-from SWIFT_DATA -t morrisjobke/docker-swift-onlyone

In the above command we have set restart flag to always restart the container regardless of the exit status, used storage volume SWIFT_DATA we created earlier and docker file mentioned earlier and redirecting port 8080 on docker instance to 12345 on host machine.

In order to connect to our swift docker instance we need to install python swiftclient:

sudo apt-get install python-swiftclient

The syntax for running the swift client commands is:

swift [-A *Auth URL*] [-U *username*] [-K *password*] command_name

Run the following command to test connection your instance:

root@HOMEPC:~# swift -A http://127.0.0.1:12345/auth/v1.0 -U test:tester -K testing stat
Account: AUTH_test
Containers: 0
Objects: 0
Bytes: 0
X-Put-Timestamp: 1488029601.92136
X-Timestamp: 1488029601.92136
X-Trans-Id: txe6416999544e40e79a535-0058b187a1
Content-Type: text/plain; charset=utf-8

Here auth url points to port 12345 of host machine’s localhost which will be redirected to port 8080 of docker container,username is tester from usergroup test and password is testing.The stat command returns basic information about the user’s account.

Alternatively if you would like to run commands directly instead of specifying authurl,username and password each time you can set them as environment variables in your bashrc file as follows:

Run the following command to open bashrc file:

sudo gedit ~/.bashrc

Paste the following code at the end of the file and save the file:

export ST_AUTH=http://127.0.0.1:12345/auth/v1.0
export ST_USER=test:tester
export ST_KEY=testing

Next run the following command to allow swift client to load the parameters from shell environment:

source ~/.bashrc

Now you can run all the commands directly like:

root@HOMEPC:~# swift stat
Account: AUTH_test
Containers: 0
Objects: 0
Bytes: 0
X-Put-Timestamp: 1488029796.90542
X-Timestamp: 1488029796.90542
X-Trans-Id: tx0b3db42bd57e4bbbac0ed-0058b18864
Content-Type: text/plain; charset=utf-8

The list of available commands in swift client are:

  • Stat command to display container information:
swift stat <container name>
  • Upload command to upload files:
swift upload <container_name> <file_to_upload>
  • For example to create simultaneously create container named CloudPics and upload picture.png to it run the following command:
swift upload CloudPics picture.png
  • Download command to download files from container:
swift download <container_name> <file_to_download>
  • Example:
swift download CloudPics picture.png

List all the contents of a container:

swift list <container_name>

For example to list all the contents of CloudPics container:

swift list CloudPics
picture1.png

That concludes today’s tutorial.This tutorial was inspired from original blog post on running openstack swift in docker on virtualbox,vagrant or vmware which can be found here.

Bonus Tip:

If you like to run openstack swift only for cloud storage in production environment then swiftstack might be a viable option to try.

Connect Deeper:

In the next tutorial I am going to cover how to store files uploaded by users into swift using reactjs for frontend web interface and nodejs in the backend so follow our facebook page to get notified about upcoming tutorials here: Technoetics or simply follow me on medium.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.