Showing posts with label docker. Show all posts
Showing posts with label docker. Show all posts

Monday, September 23, 2019

Running Rust Service in Kubernetes with only 3.5MB

Rust is a very exciting language. Not only for system programming but also for microservices and business development. Today I will show how we can create a simple service application in rust using Iron Framework. For this blog post, we will build a rust binary and run both in Docker and Kubernetes. In order to run kubernetes locally, I will be using minikube but you can use any kind of kubernetes cluster or distribution and it should work just fine. The most amazing thing is that we can build a rust executable with only 3.5MB and a docker image with the only 3.63MB. This is super lean!



Talk is Cheap, show me the Code!

Here we go.  Behold the main.rs file.


Here we are using Iron Web Framework and also ust env utilities in order to access OS level Env variables. The server is running on the port 8080, there is a function called hello_world with revices a request from icon a returns an Iron result with a Response. Inside the function I'm defining a key, which is a simple string that represents the env var I'm looking for, in this case, called: RUST_SVC_VERSION. After that, I'm using env_var_os to check if the var is present, also using the good rust pattern matcher to see if their var is present or not. IF The var is present I will receive Some otherwise none. In the case that the var is empty I'm returning an undefined version of the app on the response otherwise I return the value of the var concatenated with the String Hello World! V:.

We need to declare an Iron dependency in Cargo.Toml file.



Now Let build our Rust application, we will use docker to build the app, we do this way. Let's take a look at release-rust.sh file.


Here we are using rust builder in order to build the binary in an optimized way. Now we can take a look at the Dockerfile.


As you can see the Dockerfile is dead simple, we just add 1 file, which is the binary we just built and we expose the port 8080. Call the binary as main CMD from Docker and that's it, folks. Let's bake this docker image doing:


Now that we build it, we just need to run it. Let's run it by doing:


As you can realize here, I'm passing an env var to docker, with version 1, feel free to change the value and see that it works.

Let's run it with Kubernetes now. Let's take a look at the deployment and service specs.


For the deployment yaml file (^^^) as you can see we are using my docker image we just built. This image is also in my docker hub, so thats why you dont need perform any craziness to run in your minikube :D


Now we have the service yaml file (^^^) keep in mind we dont want use ClusterIP in production folks this is just for development and fun.  Having this 2 specs, we can create a folder called specs and we can deploy them to kubernetes using kubectl.


After the deploy, we can expose our service via port-forwarding and then we can call it :D


In the script above I'm using kubectl to select the pod I want using selectors, a great feature from kubernetes, I'm getting the name of the pods with the app==rustapp. Them storing this result in a bash variable and calling kubectl port-forwarding on this pod. I'm binding container 8080 port to my 8080 local port. That's it, now you can just do: curl http://localhost:8080/ and you will see it works.

Here is the complete source code in my github.

Cheers,
Diego Pacheco

Tuesday, February 5, 2019

Running istio with docker-compose and consul

In my previous post, I showed how o install and run istio locally with minikube. However, if you don't have 8GB of ram FREE it might not be a good FIT for you. Today I want to show a lightweight approach for a local environment where we can run Istio with Docker, Docker-Compose, and Consul.

I will be doing more posts about istio, this week, talking about how to run Istio on AWS for instance. But going back to this post.

In order to have this solution working in your machine you have some pre-requirements such as: have docker installed, docker-compose installed and kubectl installed.  Running with consult and docker-compose is way easier than running with minikube/kubernetes however you are not as close as the production topology. For istio, we will be using istio version 1.0.5 Let's get started!




Installing and Running Istio in Docker-Compose and Consol



Cheers,
Diego Pacheco



Monday, June 18, 2018

Running Ansible with Docker

Ansible is a great provisioning tool. However, it can be painful to get some ansible scripts right. Especially if you need some stuff with bash and Ansible. Often baking time in AWS can be pretty high. So It's better you can run ansible locally. However, running ansible local could mess up with your OS. So the best thing is run ansible in Docker. Since the docker container will be ephemeral, once you finish running the container all changes will be lost. You also will benefit from running locally and being able to figure it out quickly whats wrong.  So today I want to share about some simple project I create in order to help to do that. This is called Ansible-Docker this is an ansible sandbox using Amazon Linux.

Getting Started

In order to get started, we need have docker and git installed. Next, we need to git clone ansible-docker and then bake it. Bake just need to happen 1 time. Baked might take some time depending on your internet connection. After baking you can run "run" command which will run ansible linter and then ansible on docker image.



The Ansible Project

For this ansible sandbox, we have simple and default ansible project structure. Which you can see here on the src folder.  There is main.yml which is the file it will be run by ansible. You can see this file delegates to a git role in ansible which is located in roles/git/tasks/main.yml



The Dockerfile

Now let's take a look at the Dockerfile. So here are installing Ansible and we are using Amazon Linux Latest version as our base Docker image. As you can see on the Dockerfile we call run.sh which will run ansible as soon as the container get up. You might see a different path that happens because I'm doing some volume mapping - You can check it out here.



That's it. Now we can run ansible locally with ansible-docker. Using this ideas and scripts you can speed up your development time.

Cheers,
Diego Pacheco

Mocking Terraform AWS using Docker

Terraform is a good tool for infrastructure provisioning.  However to test terraform it could be pretty difficult. So you will create some terraform scripts and upload to the cloud a run some slow Jenkins job? and if your syntax is wrong? Well, this process can be very painful. So I want to share some simple sandbox I built in order to speed up terraform + aws development in your local machine. I might be wondering how is that possible─? Well, my secret sauce is Localstack. So we are limited to all endpoints that localstack mocks. As Localsttack adds more endpoints we benefit from that. The main idea behind this simple project is to show how easy is to docker-ize somDevOpsps tools and make engineering easy.  Currently is very often to spend 40mim or more doing baking and that's is wrong. So that's kind of mainframe era so the idea is to save time and run things local - as much as possible. Docker helps a lot with that. I run software in production using AWS Amazon Linux. Now there is Amazon Linux docker image.  This is great because you can have some OS local as you will have it in PROD.



Getting Started

First of all, you need to have Docker and git installed. Them you can clone Terraform-Docker. Once you clone docker-terraform you can run bake command. That's needed just 1 time.  After baking the docker images we can run localstack(this will need to be in another terminal). After running Localstack we can run terraform-docker.

The Terraform Project

Under the src directory you will see:

  • main.tf:        Which is our terraform "code"
  • outputs.tf:     Which are all the things Terraform will output when it finishes.
  • variables.tf:  Which are custom variables and parameters we use for terraform.
For this sample, I will create a bucket on S3 using terraform. There are some special changes that need to be made in order to this work locally. For instance, we need to point to Localstack endpoints instead of AWS ones. 


So this file is where you can see a specific IP for the S3 endpoint. I can do this because I created a Docker Network which allows me to control and define IP address for docker networks. You can see how I create a docker network and attach IPs here.

The Dockerfile

Dockerfile is pretty simple. We are using the latest Amazon Linux as base Docker image and we are installing terraform 0.11.7 and we are copying local terraform project. There is a run.sh which pretty much does terraform init and terraform apply in order to run terraform as soon as you start this container.



That's it! Now we mocked Terraform and are running all in the local machine. You can get a full project with all source code and scripts here.

Cheers,
Diego Pacheco

Sunday, April 15, 2018

Mocking and Testing AWS APIs with TestContainers and LocalStack

Cloud Computing is the default today. I do believe the future is containers and multi-cloud solutions. However today I work a lot with AWS. There are specific endpoints such as S3, AutoScaling, Route53 and other that are among the ones I use more in my day to day work. AWS API is easy to use however not no easy to test. Distributed systems tend to be hard to test. Having quick feedback is very important for engineers. There is some kind of tasks that need to interact with AWS APIs like S3 for backups for instance. However, if you need to wait to deploy in AWS to test it because is basically impossible to test it locally then we have a problem. We need to be able to do end-2-end testing however while you are coding or doing some troubleshooting is important to do things faster. There are 2 specific projects that can help us with this task. TestContainers and LocalStack. Today I will show to use LocalStack and TestContainers together with JUnit in order to do unit tests mocking S3 API. I will show how to do this using Java8. So Let's get started!

Running LocalStack locally

In order to run LocalStack locally we need to have Python and Docker installed. After you install them we can get and run LocalStack.



After you run LocalStack docker container make sure you shut down because when we run with TestContaoiners we will be able to do it over JUnit.

Setting Up Gradle Project

Now we need to set up a gradle project. Let's take a look at the build.gradle file.



Great. Now we can proceed and work with localstack and testcontainers together.

Hacking to use Latest LocalStack Image

There is a java project on TestContainers that does the Integration between LocalStack and TestContainers we will hack that project because we want to use the latest version of LocalStack. Right now the code is using an old version. So let's take a look at the code.



The changes I did above are quite simple - I just change the docker tag from 0.6 to latest and rename the name of class + enum and that's it.  Now we can move to testcontainers test code.

Testing S3 API and Running with TestConainers

Now we can focus on the unit test and mock S3. So let's go for it.



There are some important things here we need to cover. Let's start with the Annotation @Rule. This is important because the runner will use it when JUnit boot up and will boot up the Docker container needed. In regards to LocalStack as you can see I need to pass a Specific Service/Endpoint from AWS that we want to mock.

After the Rule we initialize AWS API - It's important to note here we are passing a custom endpoint otherwise we will reach the real AWS API. Then we can use S3 API normally and all commands will go to your Docker image. So we have mocked S3 Succesful. LocalStack support most of AWS endpoints and the combination with TestContainers is killer now is very easy to test AWS specific code.

The complete code is available on my GitHub here.

Cheers,
Diego Pacheco

Wednesday, November 29, 2017

Getting Started with Dyno Queues

Dyno-Queue is an interesting queue solution on top of Dynomite. Dyno-queue uses dynomite java driver a.k.a Dyno. Dyno Queue gets all benefits from dynomite like Strong Consistency, High Availability, Stability, High Throughput and Low latency and extend to queue semantics.

I highly recommend you read Netflix post about dyno-queue.



Dyno-Queues 

Dyno-queue also extra benefits and properties such as:
* Distributed
* No external locks (e.g. Zookeeper locks)
* Highly concurrent
* At-least-once delivery semantics
* No strict FIFO
* Delayed queue (message is not taken out of the queue until some time in the future)
* Priorities within the shard

Setting up a Dynomite Cluster with Docker

For development and experimentation reason we will use a side project I created called: dynomite-docker which makes very easy to setup dynomite cluster. So let's get started and set up the cluster.

If you are running on a mac you need to use the dynomite-docker-mac.sh script instead since dynomite-docker.sh is for Linux. After running $ ./dynomite-docker.sh run_single 0.6.0 you will have a 3 node dynomite cluster up and run and you should see something like this on the console:

Now that we have dynomite cluster Up and Running with docker we can move next and create the dyno connection.

Setting up a Dyno Connection

In order to set up a Dyno connection, we will need to create 4 classes. There we go:

* DynoConnectionManager: Connects to Dynomite and returns a client in a Sync way.
* DynomiteNodeInfo: Pojo to represent dynomite nodes information.
* DynomiteSeedsParser: Parse String format for objects.
* TokenMapSupplierHelper: Provide topology information about the cluster.

This is generic so we could use this to connect in other clusters. For sake of simplicity, the DynoConnectionManager does not take parameters but as you can see the seeds comes from Archaius so we could change if we need.

All right now we can move one and use dyno-queues.

Using Dyno Queues

We just need 1 class in order to use dyno queue - it's pretty simple - let's go.

Alright so here we create a Dyno connection to dynomite using DynoConnectionManager.build() method and then we define a dyno-queue configuration. We need to be defined a PREFIX and local-rack which will be part of the KEY inside redis. IF you running on AWS Rack should be an AZ and local-rack means same AZ as your application is running so you can reduce latency.

Them we can create a RedisQueues object and push messages to a queue we can poll messages from the queue as well and we can ACK messages to. As you can see the API is pretty simple and cool. If you want you can get the full code on my GitHub.

Cheers,
Diego Pacheco

Monday, November 20, 2017

Running Multi-Nodes Akka Cluster on Docker

Akka a great actor framework for the JVM.  Akka is high performance with high throughput and low latency, resilient by Design.  It's possible to use Akka with Java however I always used and recommend you use with Scala.

Create actors systems is pretty easy however creating multiple nodes on Akka cluster locally could be boring and error-prone. So I want to show how easy is to create an Akka cluster using Scala and Docker(Engine & Docker-Compose). We will create a very simple actor system, we will just log events on the cluster however you can use this as a base to do more complex code.


Build.sbt

In this project, we will use Scala 2.12.3, Akka 2.5.6. Here we are defining these versions and also the docker configuration so we will generate a Dockerfile based on this project.



We will be using SBT 0.13.8 -- You can define SBT on the file project/build.properties

project/build.properties

sbt.version=0.13.8

We also need to add the docker plugin on SBT. We do it by editing the file project/plugins.sbt.

plugins.sbt

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.3")

OK. Now we can go to the code. Let's create a Main.scala at src/main/scala.

Main.scala



Here we have an ActorSystem and we are registering a ClusterListener which is an actor that will be notified about all cluster events and when this actor boot up he will register itself on the cluster. This registration is defined on the preStart function.

reference.conf



Here we define the cluster configurations for Akka cluster. We defined the actor provider to be akka.cluster.ClusterActorRefProvider. One big important thing here is the seeds-node these nodes need to be up in order to other nodes join the cluster. You don't need to have all your nodes as seeds usually folks add 2-3 nodes as seeds. So seeds nodes address is: akka.tcp://default@akkaseed:2552 So we need to have a node running on port 2552.

docker-compose.yml



Finally, we have the docker-compose configuration. There are only 2 containers here. Seed and node. So this will create a cluster with 2 nodes. However, we will be able to scale the node image to N nodes.

Building & Running

Now is the fun part -).  Open Linux the terminal, we need to build the Docker image and then we can run docker compose. So letś do it:

$ sbt clean compile docker:publishLocal
$ docker-compose up

That's it we have the cluster Up and running.

Akka 2 Node Cluster Running - docker-compose up

Scaling Up the Cluster

We can scale the cluster to N nodes - So right now we only have 2 nodes, Let's scala the cluster to 10 nodes. We do it with docker compose by $ docker-compose scale node=10 That's it you should have something like this.

Scaling up the cluster - docker-compose scale node=10

Akka Cluster Logs - After Scale Up to 10 nodes

This is great for development and debugging. For production, I recommend using Kubernetes. You can get all the source code on my GitHub here.

Cheers,
Diego Pacheco

Saturday, November 11, 2017

Running Dynomite on AWS with Docker in multi-host network Overlay

Dynomite is a kick-ass project. Basically, allow you to have strong consistency on top of NoSQL Databases. I've been using dynomite for a while in production(AWS) and I can say the core is rock solid and it just works.

Lots of developers use Windows or Mac for instance and dynomite is built in C and it's really meant for Linux(Like all good things).  So some time ago I made 2 simple projects to get started quickly with dynomite.  Basically, the project creates a simple dynomite 3 node cluster and let you run on your local machine with docker.

There are 2 projects - One to create a dynomite cluster with Redis -- The other with Facebook's RocksDB(Experimental). So you can use it on your local machine to Debug and it works just fine. So why not go 1 step further and run Dynomite in AWS using docker? There are cool benefits if you do this approach.

Running Dynomite on AWS with Docker

Dynomite works very well on AWS but also in any other cloud-vendor or Bare metal DC. Dynomite runs on Docker just fine too. Now you can choose to run on EC2, ECS, Kubernetes on EC2 or even EC2 with docker.

The Benefits

There are many advantages do run Dynomite with docker on aws.

Here are some Benefits -- The good things:
 - COST Savings: Since you can benefit from your reservation and do better resource utilization.
 - Less Latency: Running on docker allow you to easily deploy on the same box as application and reduce network roundtrips.
 - Portability: Same docker image can be used to run anywhere also from the developer machine.
 
The Cons

Like everything in life, there are pros and cons. Here are some I found:

- Networking: Docker networking can get very tricky and hard to maintain.
- Size Limitations: Default network in /24 so it's limited to 256 ips. Offcourse you can create more networks.
- More Complex: You will have docker, docker cluster(swarm), docker network(overlay) to managed so there are more moving points of failure compared with just running dynomite on EC2 for instance.

Getting Started 

Now we will install Docker, Docker Swarm, Configure a docker cluster, Create a network overlay and run dynomite in a cluster in Docker on Ec2. Phew! Long list. :-)



We will do something very silly and simple. So will deploy a 3 node cluster. This cluster won't have sharding(You can have sharding on dynomite - just dependents on seeds config - for sake of simplicity we will not do it) or cold bootstrapping or S3 backups - If you are interested in this feature you should take a look in Dynomite-Manager.

Basically, we need do the following steps in order to get this working. These are the steps:
 1.  Create EC2 instances(Let's say 2) - Later you can automate(Ansible, Boto3, Terraform, whatever)
 2.  Create Security Groups(Use the same SG for all ec2 instances) like sg_dynomite_docker.
 3. You need open ports(SG): 8101, 8102, 6379, 2377 and any others your app might need.
 4. Them we ssh to the box and install Docker
 5. Install docker Swarm - become a master - Docker will give you the command.
 6. Do ssh to the other box and they join the master swarm node.
 7. Create a Docker network with overlay - make sure it's attachable.
 8. Configure dynomite YAML files to use fixed ips on the docker network overlay.
 9. Do docker run and run docker dynomite container 2x in 1 host
10. Do docker run and run docker dynomite on another host. That's it.

You can use my dynomite-docker project as a starting point and make the changes there because there are configs and Dockerfile done you just need change the IPs and remove the volume mapping and make sure you create the docker network with overlay as that's it. Here there is a https://gist.github.com/diegopacheco/6c75a445337e1ac29fd9ae07a16e2500 sample snipper that might help you.

Cheers,
Diego Pacheco

Thursday, July 27, 2017

Kubernetes with Docker and Minikube

Kubernetes is getting more popular every day. Kubenertes is an open source system for automating deployments, scaling and managing containerized applications. Created by Google on 2014 and also know as k8s. Why? Because there are 8 letters between k and s :-).

K8s has many features such as Automatic bin-packing which is the capability of placing containers based on resources and constraints.  K8s also has horizontal scaling, storage orchestration using local storage or cloud storage such as AWS or GCP.

K8s has important Cloud native capabilities such as Self Healing, Service Discovery and Load Balancing and secret and dynamic config management. For this blog post, we will see how to bake a simple docker image using node js application and deploy this docker image on hibernates using minikube in order to run locally.

There are other cloud-native solutions such as NetflixOSS Stack. Also Spring Cloud, which uses NetflixOSS too. However, on this post, we will be focusing on Docker and Kuerbenete .


Running Minikube on Ubuntu Linux 17.04

You can do it with other Linux distributions such as 16.04 LTS for instance, however, I will show in Ubuntu Linux 17.04 because of thats the distro I'm currently using. In theory, it should be very straight forward to get Minikube up and running on Linux. However is not that easy. If you search on the internet you will see lots of people complaining about:



Some people spend days to figure this out, lots of open issues on GitHub and threads on stack overflow. Las t night I spent 3hours to figure out what was going on.

There are also sorts of trying this, try that. Some folks said Minikube is not stable on Ubuntu Linux 17.04 but actually that all wrong. The issue is Virtualbox. Every time I update VirtualBox something stop working like Vagrant, Docker or Kubernetes. So the fix is pretty simple but you need to keep in mind that every time you update VirtualBox you need do this.


Installing Minikube and kubectl

Alright! Let's get down to business and install Minikube and kubecetl on our Linux. First commands will wipe out all previous installations this works well for the first time installs and also for upgrade scenarios. The beauty of minikube is you can continue working normally with kubectl console tool. So there is no difference if you running minikube locally or running k8s on GKE or AWS with Kops.It all works in the same way.


Baking NodeJS Docker image 

So let's build a simple node js application and also bake a docker image with this application. Let's get to the Javascript code. The main reason I'm showing this code in JavaScript is that is some small and concise. We could do it in other languages but for sake of simplicity and focus on Kubernets and minikube let's go with JS.


We also need to have a Dockerfile in order to bake the image. Ther we go.


Deploying to Kubernetes

Now it's time. Let's start minikube and push this docker image to minikube dockers registry and see this app running on our local Kubernetes.

There are some important things to keep in mind such eval $(minikube docker-env) which does the trick to integrate our local docker with minikube. Otherwise, the kubernetes registry will try to download images from public docker hub.

 

You also can take a look on the kubernetes dashboard and check our app if you want. To do it so you do $ minikube dashboard and go to http://192.168.99.100:30000/#!/workload?namespace=default As you can see your image is there. This dashboard is very useful you can use it to check information about your containers and also deploy new containers.


All right that's it. Have fun!

cheers,
Diego Pacheco

Wednesday, July 5, 2017

Dynomite and RocksDB running on Docker

Dynomite is a kick ass cluster/proxy solution that provides high availability and strong consistent to databases. Dynomite was created and battle tested by Netflix using Memcached and Redis as primary store backend.

RocksDB it's a Facebook Embedded Key/Value store which is growing up a lot because of his incredible high performance and low latency.

For this blog post, I will show some simple project I create for the developers to get started with Dynomite and RocksDB together. This project uses docker and creates a Dynomite cluster using RocksDB as backend.

Let's get started...




Dynomite Super Powers

Dynomite is interesting for many reasons but one very simple and limited way to see Dynomite as a supercharged Redis with batteries included. Why not use ElastiCache(Amazon Redis managed service) well because first of all you should think twice before get fully coupled to Amazon or any public cloud vendor.  In the beginning, it might look like a good idea since you have all sorts of services that are integrated but there are many limitations and as you get a vendor LOCK IN you won't be able to get better and cheaper competitors offers and also it can be less available. I guess everybody remembers last S3 outage almost tear down the whole with it. If you have a portable solution you can run your solution in other cloud vendors like Google or Azure. Solutions like Spinnaker can help you a lot with that but they won't help you if your persistence system is fully coupled to one vendor.

IMHO because Dynomite is based on Amazon Dynamo paper still has superior clustering solution them original Redis cluster(Master/Slave) and elastiCacheit's pretty much the same cluster as OSS Redis Cluster but managed by AWS.

Another more comprehensive and correct way to see Dynomite is looking as a Generic Supercharger because as long as you have something that talks Redis protocol you can benefit from all Redis ecosystem and Dynomite as well.  There is a very nice project which helps on that front called ARDB.

Dynomite-Docker-RocksDB project

Basically this a very simple and tiny project. Where I have some bash scripts to create Dynomite clusters using ARDB and RocksDB as persistent backend. Let's see how to get started. First of all, you need to make sure you have Docker installed on your Linux.

Cheers,
Diego Pacheco


Wednesday, April 27, 2016

VirtualBox Hell on Windows 10

Currently, Docker and even Vagrant are difficult to use on Windows 10. As far as I know the VirtualBox is not being stable at all. That's why these last versions of docker and vagrant were being so unstable and given too much head-ache.
IF you have to work with a windows station I recommend not update this stack if is working for you. Some months ago I ran into serious trouble and spend lots of time to fix it.   If you are having networking issues with Vagrant or Docker on windows 10 I might have the solution for you. It works for me. :-)


Saturday, June 20, 2015

Vagrant: Ubuntu 14.04 with Docker 1.7

Boot2Docker is great however it has some limitations. For instance the OS is readonly and came with pretty much nothing, setting up a shared folder in windows is challenging as well as i showed on last post.  In this post i come to show something different and easier than the previous solution. You can use docker with vagrant if you are a windows or mac user this is better than use boot2docker because IMHO you can do it easily and with less software and you also gain a linux os with you can do stuff because is not read only. Let`s use Vagrant.

Setting up Vagrant

Vagrant will install virtualbox for you the vagrant installation is pretty straightforward, so after you download and install vagrant you just need run $ vagrant init ubuntu/trusty64
Vagrant will create a Vagrantfile for you. It`s a very simple ruby DSL, vagrant allow you to provision a machine using the most cool and modern configuration management / automation engines solutions like Puppet, Chef, Ansible and even Docker.

We will need edit the Vagrantfile in order to install docker for us :-) We also will setup a shared folder with windows, which is very easy, just 1 line of config. So Copy this content and you into your Vagrantfile

Setting up Docker and Docker Compose

Now we can create the machine and do provision with shell, i did not use any of the automation solutions like ansible because this is so straightforward and the shell works for this, however in a production scenario i really recommend you use ansible or chef.

You can realize there is a config for: config.vm.synced_folder this is who we create a shared folder with vagrant  and windows, you just need to have a folder called shared in the same directory you have your Vagrantfile.

The provision happens with shell script, most apt-get install commands, from line 10 to 19. This is happen just once if for same reason you want run them again you can do $ vagrant provision and vagrant will re-run all the shell commands.

You are ready to rock and have fun, now just run $ vagrant up && vagrant ssh
Vagrant will download and install docker 1.7 and docker-compose for you. On the linux machine you can run $ sudo docker run hello-world

Here we go with the inception

That`s all great but lets say i want to run a ubuntu container with docker, well then you just do $ sudo docker run -i -t ubuntu /bin/bash 

Right, but now i want get that windows shared folder i have shared with my vagrant ubuntu linux 14.04 and i want share that with the ubuntu with docker inside vagrant? That`s piece of cake now, docker has the -v option you can map shared folders, you just need do this:
$ sudo docker run -v /home/vagrant/shared/:/home/ubuntu/shared -i -t ubuntu /bin/bash

IF you want all the files you can download from my git hub https://github.com/diegopacheco/Diego-Pacheco-Sandbox/tree/master/DevOps/vagrant-with-docker

Cheers,
Diego Pacheco

Tuesday, May 26, 2015

Docker Shared folder on windows

Docker is ultra hot right now. It`s becoming a standard very quickly.  There are some issues on IO and Network but still a very promising solution for prime time. If you are a developer and are working on a Windows machine docker is great for you because you can have linux almost for free :-) For Mac and Windows users we need use Boot2Docker. Boot2Docker is a very small image lass them 30MB and is ultra fast it uses tiny linux kernel. Let`s see how to have a shared folder in windows and a docker container using ubuntu inside docker :-) This should be included at the official boot2docker image at some point but for now or you build the image or you do a workaround.




Getting VirtualBox

Make sure you have the latest version of virtualbox installed. Youcan download it here: https://www.virtualbox.org/wiki/Downloads

Getting Boot2Docker

First of all you need get boot2docker, here: https://github.com/boot2docker/windows-installer/releases current version now is 1.6.2. There only one problem, boot2docker does not have support for Virtual Box Guest Tools :(.  You can read more on this pull requests:

https://github.com/boot2docker/boot2docker/issues/43
https://github.com/boot2docker/boot2docker/issues/232
https://github.com/boot2docker/boot2docker/pull/534

Workaround to have the shared folder working on Windows

First of all you need download the image(you can build a more recent image if you want go check the links on the previous session) with virtualbox guest tools instaled, you can get it here: http://people.renci.org/~stealey/boot2docker/boot2docker.iso You will need do replace your boot2docker image with this one, i recomed you do a backup. Your boot2docker should be installed here: C:\Users\YOUR_USER\.boot2docker\boot2docker.iso

You will need stop boot2docker with $ boot2docker stop and them run the virtualbox command.

Them you will need create a script to use the VirtualBox API in order to create the shared folder.
With this script you can run it like this to create your shared folder:

Once you do that you can start boot2docker with

$ boot2docker start
$ boot2docker ssh

Mounting the shared folder on docker(boot2docker)

Start your boot2docker and them enter in your console and type:

A Little Bit of Inception

Let`s see i want to propagate this shared folder to another container inside docker, lets use a ubuntu image, you can do like this(now there is a docker command for it :-) ):

Shared Folders with VirtualBox on Windows still slow :(. I did a simple benchmark running a simple Node.JS code on my windows and them on this ubuntu/docker and the performance with the shared folder is slow but it`s okay to have fun a learn docker. For something more professional i recommend you consider Docker-Machine with Amazon driver.


Chuyên mục văn hoá giải trí của VnExpress

.

© 2017 www.blogthuthuatwin10.com

Tầng 5, Tòa nhà FPT Cầu Giấy, phố Duy Tân, Phường Dịch Vọng Hậu, Quận Cầu Giấy, Hà Nội
Email: nguyenanhtuan2401@gmail.com
Điện thoại: 0908 562 750 ext 4548; Liên hệ quảng cáo: 4567.