Docker is a tool for building environments and installing software on target systems. Here is a simple overview of what Docker is and a simple example.
Docker is a key component of any devops or other automated build process. It’s like Puppet or Chef, which are tools for pushing out builds. Those let you write a script to do things like configure virtual networks, install software, and run commands.Docker is small and simple. So, you can easily do a small test to see how it works and how you might use it. We show you how to do that here.Docker is a small Linux, Mac, or Windows container (image) to which you can add commands. So it’s like a tiny little Linux, Mac, or Windows OS that you can use to do something like install and configure Hadoop or Nginx on a target server. You run that image from the command line of any those operating systems.The container is necessary because installing Hadoop or Apache or anything like that requires an operating system. But what Docker does it lets you do is abstract that layer so that it can run anywhere. That’s consistent with the Devops philosophy of Infrastructure as Code.Docker is best illustrated with a small example. Here we will create the smallest possible Docker program, the Hello World program.
First, you install Docker. There are several different ways to do that, but on Ubuntu we used this:sudo curl -fsSL https://get.docker.com/ | sh They make sure it is running by checking:ps -ef | grep docker Note: If you get any errors related to TLS when you are running Docket then either Docker is not running or you need to use sudo to run it as root. You can use sudo usermod -aG docker (username) to add a user to the Docker group so that they can run that.
Now create a directory and create a file there called Dockerfile. Copy the contents of the next two lines intothat.FROM busybox RUN echo "Hello World!"The first line means the base image to use. We could have used, for example, Ubuntu. But that is large (about 64 MB) and we do not need a full base image to do a simple Hello Word. So we use the smallest possible base image BusyBox.The second command is the RUN command. Here we just run the Linux command echo. We could have done something else like RUN apt-get (something).When we run it:sudo docker build -t helloword . It looks like this:Sending build context to Docker daemon 2.048 kBStep 1 : FROM busyboxlatest: Pulling from library/busybox385e281300cc: Pull completea3ed95caeb02: Pull completeDigest:sha256:4a887a2326ec9e0fa90cce7b4764b0e627b5d6afcb81a3f73c85dc29cea00048Status: Downloaded newer image for busybox:latest---> 47bcc53f74dcStep 2 : RUN echo "Hello World!"---> Running in 0218e43aedd8Hello World!---> 737ed2d177f9Removing intermediate container 0218e43aedd8Successfully built 737ed2d177f9Docket downloads the Busybox image and runs our simple command. It also has now created a Docker image that we can see with sudo docker images.The -t helloword creates a tag (image name). The period (.) means look for the Dockerfile in the current folder.
If this example seems simplistic, it is, but that was our goal. RUN is just one command. There are many more commands like ENV to set environment variables and EXPOSE to let the Docker image communicate over the specified port with the host operating system as it executes.Now, to continue learning, you could create your own Docker repository following the Getting Started instructions from Docker and upload the Docker image you just created there. You can also browse the public repositories to see the many images other people that people have created.Everything you need to know about outsourcing technology developmentAccess a special Introduction Package with everything you want to know about outsourcing your technology development. How should you evaluate a partner? What components of your solution that are suitable to be handed off to a partner? These answers and more below.