This tutorial will explain the fundamentals of Docker and start you with some basic usage.
Docker is open source software to pack, ship and run any application as a lightweight container. Containers are completely hardware and platform independent so you don’t have to worry about whether what you are creating will run everywhere.
In the past virtual machines have been used to accomplish many if these same goals. However, Docker containers are smaller and have far less overhead than VMs. VMs are not portable as different VM runtime environments are very different. Docker containers are extremely portable. Finally, VMs were not built with software developers in mind; they contain no concept of versioning, and logging/monitoring is very difficult. Docker images, on the other hand, are built from layers that can be version controlled. Docker has logging functionality readily available for use.
You might be wondering what could go into a “container”. Well, anything! You can isolate pieces of your system into separate containers. You could potentially have a container for nginx, a container for MongoDB, and one for Redis. Containers are very easy to setup. Major projects like nginx, MongoDB, and Redis all offer free Docker images for you to use; you can install and run any of these containers with just one shell command. This is much easier than using a virtual machine (even with something like Vagrant).
Installing Docker is very easy. Visit the official Docker installation page and follow the instructions tailored for your operating system. There are simple installers for both Mac OS X and Windows.
After you’ve installed Docker, open the terminal and type the following:
$ docker info
If your installation worked, you will see a bunch of information about your Docker installation. If not, you will need to revisit the install docs.
Every Docker container is an “instance” of a Docker image. There is a massive library of pre-built Docker images. However, in order to really understand Docker, you should create an image as an exercise.
Let’s create a Docker image for running Redis. Redis is an easy to use in-memory key/value store. It is commonly used as an object cache for many different platforms across many different environments and programming languages.
Remember how I said Docker images are built from layers? Well, every Docker image has to start with a base layer. Common base layers are Ubuntu and CentOS. Let’s use Ubuntu. (In production I would use Debian since it is much smaller.)
The following command will start a Docker container based on the
:latest is called the image tag and in this case refers to the latest version of Ubuntu. If you don’t have the image locally, it will download it first. The container will be started in a bash terminal. Run the following:
$ docker run --name my-redis -it ubuntu:latest bash
-it let’s us interact with our container via the command line.
--name just gives us a convenient way to reference our container. You should now be inside your container in a bash terminal seeing something like this:
As you can see, you are logged in as root to the container so no need for
sudo. The Ubuntu base image is very bare bones. An important stratey for creating Docker images is keeping them as light as possible. Therefore you have to install a lot of things you normally just have. First, let’s install
$ apt-get update $ apt-get install wget
We need a few other things to build Redis from source and run it:
$ apt-get install build-essential tcl8.5
Now let’s install Redis:
$ wget http://download.redis.io/releases/redis-stable.tar.gz $ tar xzf redis-stable.tar.gz $ cd redis-stable $ make $ make install $ ./utils/install_server.sh
This downloads the newest version of Redis, builds it from source, and runs the installer. You will need to answer some configuration questions. Just use all the defaults. Now start Redis by running the following (it might already be started):
$ service redis_6379 start
You now have Redis started in a Docker container. The next step is saving your image. We want to be able to save the image as it is so we can distribute it and use it elsewhere.
Note: this container is an example, and is missing some things to make it truly usable such as port mapping. We will make a production ready image in the next section.
Exit your container by running:
Note that your container is now stopped since you exited bash. You can easily configure containers to run in the background though.
Run the following command:
$ docker ps -a
This command shows us all of our docker containers, running or stopped. See the container tagged with
my-redis. That’s the one we created! Now let’s commit our container as an image:
$ docker commit -m "Added Redis" -a "Your Name" my-redis tlovett1/my-redis:latest
This command compiles our container’s changes into an image.
-m specifies a commit message, and
-a let’s us specify an author.
tlovett/my-redis:latest is formatted author/name:version. Author refers to your username on Docker Hub. If you don’t want to push your image to the Docker Hub, then this doesn’t matter, and you can use anything you want. If you do, you will need to create an account and use
docker push to push the image upstream.
Docker commit creates an image containing the changes we made to the original Ubuntu image. This makes distributing Docker containers super fast since people won’t have to re-download layers (such as Ubuntu:latest) that they already have. In a container, every time you run a command, add a file or directory, create an environmental variable, etc. a new layer is created. Docker commit groups these layers into an image. When distributing Docker images, you should carefully optimize your layers to keep them as small as possible. This tutorial does not cover layer optimization.
You might be thinking that this is somewhat messy since your container is basically a black box. What if you want to redo your image? Would you have to write down the steps to reproduce the entire thing? What if you wanted to recreate your image from CentOS instead of Ubuntu? Your thinking would be correct. Creating Docker images in this way is not the best idea. Instead you should use Dockerfiles.
A Dockerfile is a set of instructions written as a shell script for creating a Docker image. Let’s create a Dockerfile that generates an image like the one we just created manually but with some important additions.
Create a file called
Dockerfile. Paste the following into the new file:
FROM ubuntu:latest RUN apt-get update RUN apt-get install -y wget RUN apt-get install -y build-essential tcl8.5 RUN wget http://download.redis.io/releases/redis-stable.tar.gz RUN tar xzf redis-stable.tar.gz RUN cd redis-stable && make && make install RUN ./redis-stable/utils/install_server.sh EXPOSE 6379 ENTRYPOINT ["redis-server"]
There are some special things in this Dockerfile.
FROM tells Docker which image to start from. As you can see, we are starting with Ubuntu.
RUN simply runs a shell command.
EXPOSE opens up a port to be publically accessible. 6379 is the standard Redis port.
ENTRYPOINT designates the command or application to be run when a container is created. In this case whenever a container is created from our image,
redis-server will be run.
Now that we’ve written our Dockerfile, let’s build an image from it. Run the following command from within the folder of your Dockerfile:
$ docker build -t redis .
This command will create an image tagged
redis from your Dockerfile.
Finally, let’s create a running container from our image. Run the following command:
$ docker run -d -p 6379:6379 redis
That’s it! Now you have Redis up-and-running on your machine.This container/image is production ready.
Docker is a powerful tool for creating and running distributable, lightweight applications both locally and in production.
There are many tools and services available to be used in Docker. For example, Dockunit is a tool powered by Docker that lets you test your software across any environment. This tutorial has just scratched the surface of the Docker world.
In this tutorial we’ll learn how to begin programming with R using RStudio. We’ll install R, and RStudio RStudio, an extremely popular development environment for R. We’ll learn the key RStudio features in order to start programming in R on our own.
If you already know how to use RStudio and want to learn some tips, tricks, and shortcuts, check out this Dataquest blog post.
[tidyverse](https://www.dataquest.io/blog/tutorial-getting-started-with-r-and-rstudio/#tve-jump-173bb264c2b)Packages into Memory
#data science tutorials #beginner #r tutorial #r tutorials #rstats #tutorial #tutorials
Docker is an open platform that allows use package, develop, run, and ship software applications in different environments using containers.
In this course We will learn How to Write Dockerfiles, Working with the Docker Toolbox, How to Work with the Docker Machine, How to Use Docker Compose to fire up multiple containers, How to Work with Docker Kinematic, Push images to Docker Hub, Pull images from a Docker Registery, Push stacks of servers to Docker Hub.
How to install Docker on Mac.
#docker tutorial #c++ #docker container #docker #docker hub #devopstools
Following the second video about Docker basics, in this video, I explain Docker architecture and explain the different building blocks of the docker engine; docker client, API, Docker Daemon. I also explain what a docker registry is and I finish the video with a demo explaining and illustrating how to use Docker hub
In this video lesson you will learn:
#docker #docker hub #docker host #docker engine #docker architecture #api
In this blog post, we’ll look at how to use R Markdown. By the end, you’ll have the skills you need to produce a document or presentation using R Mardown, from scratch!
We’ll show you how to convert the default R Markdown document into a useful reference guide of your own. We encourage you to follow along by building out your own R Markdown guide, but if you prefer to just read along, that works, too!
R Markdown is an open-source tool for producing reproducible reports in R. It enables you to keep all of your code, results, plots, and writing in one place. R Markdown is particularly useful when you are producing a document for an audience that is interested in the results from your analysis, but not your code.
R Markdown is powerful because it can be used for data analysis and data science, collaborating with others, and communicating results to decision makers. With R Markdown, you have the option to export your work to numerous formats including PDF, Microsoft Word, a slideshow, or an HTML document for use in a website.
Turn your data analysis into pretty documents with R Markdown.
We’ll use the RStudio integrated development environment (IDE) to produce our R Markdown reference guide. If you’d like to learn more about RStudio, check out our list of 23 awesome RStudio tips and tricks!
Here at Dataquest, we love using R Markdown for coding in R and authoring content. In fact, we wrote this blog post in R Markdown! Also, learners on the Dataquest platform use R Markdown for completing their R projects.
We included fully-reproducible code examples in this blog post. When you’ve mastered the content in this post, check out our other blog post on R Markdown tips, tricks, and shortcuts.
Okay, let’s get started with building our very own R Markdown reference document!
R Markdown is a free, open source tool that is installed like any other R package. Use the following command to install R Markdown:
Now that R Markdown is installed, open a new R Markdown file in RStudio by navigating to
File > New File > R Markdown…. R Markdown files have the file extension “.Rmd”.
When you open a new R Markdown file in RStudio, a pop-up window appears that prompts you to select output format to use for the document.
The default output format is HTML. With HTML, you can easily view it in a web browser.
We recommend selecting the default HTML setting for now — it can save you time! Why? Because compiling an HTML document is generally faster than generating a PDF or other format. When you near a finished product, you change the output to the format of your choosing and then make the final touches.
One final thing to note is that the title you give your document in the pop-up above is not the file name! Navigate to
File > Save As.. to name, and save, the document.
#data science tutorials #beginner #r #r markdown #r tutorial #r tutorials #rstats #rstudio #tutorial #tutorials
If you are a developer who uses Docker, odds are you may have heard that you can use volumes to maintain persistent state for your containers in production. But what many developers don’t realize is that volumes can also be an excellent tool for speeding up your development workflow.
In this post, I’ll give you a brief overview of what is a Docker volume, how docker host volumes work, and show you a tutorial and example of how you can use volumes and nodemon to make coding with Docker easier and faster.
#microservices #tutorial #docker #developer-tutorials #docker-compose